Merge branch 'master' of ssh://git.indexdata.com:222/home/git/pub/mkws
[mkws-moved-to-github.git] / test / spec / async.spec.js
index 8aa5bd5..6de372d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 IndexData ApS. http://indexdata.com
+/* Copyright (c) 2013 Index Data ApS. http://indexdata.com
  *
  * async check
  *
@@ -9,7 +9,7 @@ describe("Asynchronous check", function () {
     });
 
     // Asynchronous part
-    it("check running search", function () {
+    it("simple check", function () {
         var max_time = 1;
         var timer = 0;
 
@@ -17,6 +17,7 @@ describe("Asynchronous check", function () {
             setTimeout(function () {
                 timer = time;
             }, time * 1000);
+            expect(time >= 0).toBeTruthy();
         }
 
         runs(function () {
@@ -37,6 +38,48 @@ describe("Asynchronous check", function () {
         runs(function () {
             expect(timer).toEqual(max_time);
         });
+    });
+
+
+    it("double async check", function () {
+        var max_time = 0.5;
+        var timer = 0;
+
+        function found(time, none) {
+            setTimeout(function () {
+                timer = time;
+            }, time * 1000);
+            expect(time >= 0).toBeTruthy();
+        }
+
+        runs(function () {
+            found(0);
+            found(0.2);
+            found(max_time - 0.1);
+        });
+
+        waitsFor(function () {
+            return timer == max_time - 0.1 ? true : false;
+        }, "The Value should be N seconds", max_time * 1000);
+
+        runs(function () {
+            expect(timer <= max_time).toBeTruthy();
+        });
+
+        timer = 0;
+        runs(function () {
+            found(0.1);
+            found(max_time);
+        });
 
+        waitsFor(function () {
+            // console.log("waits for ... " + timer);
+            return timer == max_time ? true : false;
+        }, "The Value should be N seconds", max_time * 1000);
+
+        runs(function () {
+            expect(timer <= max_time).toBeTruthy();
+        });
     });
+
 });