UNPKG

818 BJavaScriptView Raw
1
2/**
3 * Tests for Sync.sleep function
4 */
5
6var Sync = require('..'),
7 assert = require('assert');
8
9var runTest = module.exports = function(callback)
10{
11 var e;
12
13 try {
14 // Test sleeping correctly
15 Sync(function(){
16 var start = new Date;
17 Sync.sleep(101); // sleep on 100 ms
18
19 assert.ok(new Date - start >= 100);
20 })
21
22 // Test throws exception when callend not insode of fiber
23 assert.throws(function(){
24 Sync.sleep(1000);
25 }, 'should throw exception when callend not inside of fiber')
26 }
27 catch (e) {
28 console.error(e.stack);
29 }
30
31 if (callback) {
32 callback(e);
33 }
34}
35
36if (!module.parent) {
37 runTest(function(){
38 console.log('%s done', __filename);
39 });
40}