forked from PencilCode/jquery-turtle
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinterrupt.html
More file actions
47 lines (47 loc) · 1.18 KB
/
interrupt.html
File metadata and controls
47 lines (47 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<script src="lib/qunit.js"></script>
<link href="lib/qunit.css" rel="stylesheet">
<script src="lib/jquery.js"></script>
<script src="../jquery-turtle.js"></script>
<body>
<div id="qunit"></div>
<script>
eval($.turtle({hangtime: 10}));
module("Interrupt test.");
asyncTest("Tests interrupts.", function() {
var gotException = false, j;
// Nothing queued, nothing interruptable.
ok(!interrupt('test'));
// Now test an infinite loop: we should kill it in 10 ms.
try {
while(true) {
rt(1);
}
} catch (e) {
gotException = true;
}
ok(gotException);
// After killing an infinte loop, queues should be cleared.
equal($.queue(turtle).length, 0);
ok(!interrupt('test'));
// Reset the interrupt so we can run commands again.
interrupt('reset');
for (j = 0; j < 10; ++j) {
fd(10);
}
// Something is running, so something is interruptable.
ok(interrupt('test'));
// Interrupting it should throw an exception.
gotException = false;
try {
interrupt();
} catch(e) {
gotException = true;
}
ok(gotException);
// And the queues should be emptied immediately.
equal($.queue(turtle).length, 0);
done(function() {
start();
});
});
</script>