-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test Dispatcher's use of WorkerPool
- Loading branch information
Anand Thakker
committed
Aug 11, 2016
1 parent
f9622cf
commit afbdafd
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
var Dispatcher = require('../../../js/util/dispatcher'); | ||
var WebWorker = require('../../../js/util/web_worker'); | ||
var originalWorkerPool = Dispatcher.workerPool; | ||
|
||
test('Dispatcher', function (t) { | ||
t.test('requests and releases workers from pool', function (t) { | ||
var dispatcher; | ||
var workers = [new WebWorker(), new WebWorker()]; | ||
|
||
var releaseCalled = []; | ||
Dispatcher.workerPool = { | ||
acquire: function (id, count) { | ||
t.equal(count, 2); | ||
return workers; | ||
}, | ||
release: function (id) { | ||
releaseCalled.push(id); | ||
} | ||
}; | ||
|
||
dispatcher = new Dispatcher(2, {}); | ||
t.same(dispatcher.actors.map(function (actor) { return actor.target; }), workers); | ||
dispatcher.remove(); | ||
t.equal(dispatcher.actors.length, 0, 'actors discarded'); | ||
t.same(releaseCalled, [dispatcher.id]); | ||
t.end(); | ||
}); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('after', function (t) { | ||
Dispatcher.workerPool = originalWorkerPool; | ||
t.end(); | ||
}); | ||
|