Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 520761 - [tests] Port the search and tasks tests - tasks
  • Loading branch information
mrennie committed Sep 7, 2017
1 parent 8129b68 commit c6c8f5d
Showing 1 changed file with 159 additions and 106 deletions.
265 changes: 159 additions & 106 deletions modules/orionode/test/test-tasks.js
Expand Up @@ -7,158 +7,211 @@
*
* Contributors:
* Remy Suen - initial API and implementation
* IBM Corporation Inc. - additional tests
*****************************************************************************/
/*eslint-env node, mocha, assert, express*/
var assert = require('assert');
var express = require('express');
var supertest = require('supertest');
var tasks = require('../lib/tasks');
var path = require("path");
var testData = require("./support/test_data");
var assert = require('assert'),
express = require('express'),
supertest = require('supertest'),
tasks = require('../lib/tasks'),
path = require("path"),
testData = require("./support/test_data"),
testHelper = require("./support/testHelper"),
store = require('../lib/metastore/fs/store'),
taskHelper = require('./support/task_helper');

var CONTEXT_PATH = '';
var username = "testUser" + Date.now();

var MEATASTORE = path.join(__dirname, '.test_metadata');
var WORKSPACE = path.join(__dirname, '.test_workspace');
var taskIds = [];
var configParams = { "orion.single.user": true, "orion.single.user.metaLocation": MEATASTORE };
var CONTEXT_PATH = '',
MEATASTORE = path.join(__dirname, '.test_metadata'),
WORKSPACE = path.join(__dirname, '.test_workspace'),
taskIds = [],
configParams = {
"orion.single.user": true,
"orion.single.user.metaLocation": MEATASTORE
};

var app = express();
var options = {};
app.locals.metastore = require('../lib/metastore/fs/store')({workspaceDir: "", configParams: configParams});
app.locals.metastore.setup(app);
app.use(CONTEXT_PATH + '/taskHelper', require('./support/task_helper').router({
root: '/taskHelper',
metastore: app.locals.metastore
}))
.use(CONTEXT_PATH + '/task', tasks.router({
taskRoot: CONTEXT_PATH + '/task',
metastore: app.locals.metastore
}));
app.locals.metastore = store({workspaceDir: WORKSPACE, configParams: configParams});
app.locals.metastore.setup(app);
app.use(CONTEXT_PATH + '/taskHelper', taskHelper.router({
root: '/taskHelper',
metastore: app.locals.metastore
}))
.use(CONTEXT_PATH + '/task', tasks.router({
taskRoot: CONTEXT_PATH + '/task',
metastore: app.locals.metastore
}));

var request = supertest.bind(null, app);

describe("Tasks API", function() {
before(function() {
testData.setUpWorkspace(WORKSPACE, MEATASTORE);
});
after("Remove Workspace and Metastore", function(done) {
testData.tearDown(WORKSPACE, function(){
testData.tearDown(MEATASTORE, done);
});
});
beforeEach(function() {
beforeEach(function(done) {
//clean up done tasks before each test
request()
.del(CONTEXT_PATH + "/task")
.expect(200)
.end(function(err, res) {
testData.setUp(WORKSPACE, function(){
testData.setUpWorkspace(WORKSPACE, MEATASTORE, done);
}, false);
});
});

/**
* From: org.eclipse.orion.server.tests.tasks.TaskInfoTest.java
*/
describe("task info tests", function() {
it("testBadJSON");
it("testJSONRoundTrip");
afterEach("Remove Workspace and Metastore", function(done) {
testData.tearDown(WORKSPACE, function(){
testData.tearDown(path.join(MEATASTORE, '.orion'), function(){
testData.tearDown(MEATASTORE, done)
})
});
});
/**
* From: org.eclipse.orion.server.tests.tasks.TaskStoreTest.java
*/
describe("task store tests", function() {
it("testRead");
it("testRoundTrip");
it("testDeleteTask");
it("readAllTasksTest");
it("testUniqueTaskInfo");
it("testRead", function(done) {
request()
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
var taskLoc = res.body.Location;
//now fetch it
request()
.get(taskLoc)
.expect(200)
.end(function(err, res) {
testHelper.throwIfError(err);
assert(res.body && res.body.type === "loadstart", "We should have been able to fetch the created task.")
//mark the task done so it will be removed
request()
.post(path.join(CONTEXT_PATH, '/taskHelper', path.basename(taskLoc)))
.expect(200)
.end(done)
});
});
});
it("readAllTasksTest", function(done) {
//create a couple of tasks
request()
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
//mark it done
var taskLoc1 = res.body.Location;
//create a second task
request()
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
var taskLoc2 = res.body.Location;
//ask for all of them
request()
.get('/task/count')
.expect(200)
.end(function(err, res) {
testHelper.throwIfError(err);
assert(res && res.body, "We should have gotten a response");
assert.equal(res.body.count, 2, "Got the wrong number of tasks back");
//mark the tasks done
request()
.post(path.join(CONTEXT_PATH, '/taskHelper', path.basename(taskLoc1)))
.expect(200)
.end(function(err, res) {
testHelper.throwIfError(err);
request()
.post(path.join(CONTEXT_PATH, '/taskHelper', path.basename(taskLoc2)))
.expect(200)
.end(done)
});
});
});
});
});
});
describe('delete all completed tasks', function(done) {
it('no tasks at all', function(finished) {
// delete all the tasks
request()
.del(CONTEXT_PATH + "/task")
.expect(200)
.end(function(err, res) {
assert.ifError(err);
// there were no tasks to begin with
assert.equal(res.body.length, 0);
finished();
});
.del(CONTEXT_PATH + "/task")
.expect(200)
.end(function(err, res) {
assert.ifError(err);
// there were no tasks to begin with
assert.equal(res.body.length, 0);
finished();
});
});

it('one running task', function(finished) {
// create a task
request()
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
var location = res.body.Location;

// delete all completed tasks
request()
.del(CONTEXT_PATH + "/task")
.expect(200)
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
// original task incomplete, still alive
assert.equal(res.body.length, 1);
assert.equal(res.body[0], location);

// mark test task as completed
var location = res.body.Location;
// delete all completed tasks
request()
.post(CONTEXT_PATH + "/taskHelper/" + location.substr(5))
.expect(200)
.end(function(err, res) {
assert.ifError(err);

// delete all completed tasks
request()
.del(CONTEXT_PATH + "/task")
.expect(200)
.end(function(err, res) {
assert.ifError(err);
// marked test task should not exist anymore
assert.equal(res.body.length, 0);
finished();
// original task incomplete, still alive
assert.equal(res.body.length, 1);
assert.equal(res.body[0], location);

// mark test task as completed
request()
.post(CONTEXT_PATH + "/taskHelper/" + location.substr(5))
.expect(200)
.end(function(err, res) {
assert.ifError(err);

// delete all completed tasks
request()
.del(CONTEXT_PATH + "/task")
.expect(200)
.end(function(err, res) {
assert.ifError(err);
// marked test task should not exist anymore
assert.equal(res.body.length, 0);
finished();
});
});
});
});
});
});
});

it('one running task, one completed', function(finished) {
// spawn a running task
request()
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
var location = res.body.Location;
taskIds.push(location);

// spawn a second running task
request()
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
var location2 = res.body.Location;
taskIds.push(location2);

// mark the first one as completed
var location = res.body.Location;
taskIds.push(location);
// spawn a second running task
request()
.post(CONTEXT_PATH + "/taskHelper/" + location.substr(5))
.expect(200)
.end(function(err, res) {
assert.ifError(err);

// check that the second running task is still there after deletion
request()
.del(CONTEXT_PATH + "/task")
.expect(200)
.put(CONTEXT_PATH + "/taskHelper")
.end(function(err, res) {
assert.ifError(err);
assert.equal(res.body.length, 1);
assert.equal(res.body[0], location2);
finished();
var location2 = res.body.Location;
taskIds.push(location2);
// mark the first one as completed
request()
.post(CONTEXT_PATH + "/taskHelper/" + location.substr(5))
.expect(200)
.end(function(err, res) {
assert.ifError(err);
// check that the second running task is still there after deletion
request()
.del(CONTEXT_PATH + "/task")
.expect(200)
.end(function(err, res) {
assert.ifError(err);
assert.equal(res.body.length, 1);
assert.equal(res.body[0], location2);
finished();
});
});
});
});
});
});
});
});
}); // describe("Tasks API")
});

0 comments on commit c6c8f5d

Please sign in to comment.