Commit 057e12b7 authored by Tristan Cavelier's avatar Tristan Cavelier

job management jio tests added

parent d4daac52
...@@ -651,44 +651,126 @@ ...@@ -651,44 +651,126 @@
}); });
/** /**
* Tests job workspace * Tests job management
*/ */
test("Job Workspace", function () { test("Job Management", function () {
var workspace = {}, clock, jio; var workspace = {}, clock, jio, o = {};
expect(2); expect(8);
clock = sinon.useFakeTimers(); clock = sinon.useFakeTimers();
jio = new JIO({ jio = new JIO({
"type": "fake", "type": "fake",
"id": "1 Job Worksp" "id": "1 Job Manage"
}, { }, {
"workspace": workspace "workspace": workspace
}); });
jio.get({"_id": "a"}, {"max_retry": 2, "timeout": 12}); // Launch a get command, check the workspace and then respond
jio.get({"_id": "a"}, {"max_retry": 2, "timeout": 12}).
always(function (answer) {
deepEqual(answer, {
"_id": "a",
"b": "c",
"ok": true,
"status": 200,
"statusText": "Ok"
}, "Job respond");
});
o.job1 = {
"kwargs": {"_id": "a"},
"options": {"max_retry": 2, "timeout": 12},
"storage_spec": {"type": "fake", "id": "1 Job Manage"},
"method": "get",
"created": new Date(0),
"tried": 1,
"state": "running",
"modified": new Date(0),
"max_retry": 2,
"timeout": 12,
"id": 1
};
deepEqual(workspace, {
"jio/jobs/{\"id\":\"1 Job Manage\",\"type\":\"fake\"}": jIO.util.
uniqueJSONStringify([o.job1])
}, 'Job added, workspace have one job');
clock.tick(1);
fakestorage["1 Job Manage/get"].success({"_id": "a", "b": "c"});
clock.tick(1);
deepEqual(workspace, {}, 'Job ended, empty workspace');
// Launch a get command which launches another get command
// check workspace after every command and respond
jio.get({"_id": "b"}, {"max_retry": 2, "timeout": 12}).
always(function (answer) {
deepEqual(answer, {
"_id": "b",
"c": "d",
"ok": true,
"status": 200,
"statusText": "Ok"
}, "First job respond");
});
clock.tick(1);
fakestorage["1 Job Manage/get"].storage({
"type": "fake",
"id": "2 Job Manage"
}).get({"_id": "c"}).always(function (answer) {
deepEqual(answer, {
"_id": "c",
"d": "e",
"ok": true,
"status": 200,
"statusText": "Ok"
}, "Second job respond");
});
o.job1.kwargs._id = 'b';
o.job2 = {
"kwargs": {"_id": "c"},
"options": {},
"storage_spec": {"type": "fake", "id": "2 Job Manage"},
"method": "get",
"created": new Date(0),
"tried": 1,
"state": "running",
"modified": new Date(0),
"max_retry": 3,
"timeout": 10000,
"id": 2
};
deepEqual(workspace, {
"jio/jobs/{\"id\":\"1 Job Manage\",\"type\":\"fake\"}": jIO.util.
uniqueJSONStringify([o.job1, o.job2])
}, 'Job calls another job, workspace have two jobs');
clock.tick(1);
fakestorage['1 Job Manage/get'].end();
deepEqual(workspace, { deepEqual(workspace, {
"jio/jobs/{\"id\":\"1 Job Worksp\",\"type\":\"fake\"}": jIO.util. "jio/jobs/{\"id\":\"1 Job Manage\",\"type\":\"fake\"}": jIO.util.
uniqueJSONStringify([{ uniqueJSONStringify([o.job2])
"kwargs": {"_id": "a"}, }, 'First Job ended, second still there');
"options": {"max_retry": 2, "timeout": 12},
"storage_spec": {"type": "fake", "id": "1 Job Worksp"}, fakestorage['1 Job Manage/get'].success({"_id": "b", "c": "d"});
"method": "get", clock.tick(1);
"created": new Date(0),
"tried": 1, fakestorage['2 Job Manage/get'].success({"_id": "c", "d": "e"});
"state": "running", clock.tick(1);
"modified": new Date(0),
"max_retry": 2, deepEqual(workspace, {}, 'No more job in the queue');
"timeout": 12, });
"id": 1
}]) /**
}, 'Check workspace'); * Test job recovery
*/
clock.tick(1); test('Job Recovery', function () {
fakestorage["1 Job Worksp/get"].success({"_id": "a", "b": "c"}); expect(0);
clock.tick(1); // create instance
// create a job
deepEqual(workspace, {}, 'Check workspace'); // copy workspace
// create instance with copied workspace
// wait for action
}); });
})); }));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment