mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-11 10:19:15 +00:00
more tests for blocking
This commit is contained in:
parent
37ba82eebf
commit
4b0bd39e1a
@ -65,6 +65,7 @@ Distributor.prototype._runNext = function(callback) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var stepCallback = this.slot();
|
var stepCallback = this.slot();
|
||||||
|
// run project on the first step two prevent parallel run next calls
|
||||||
var executor = node.run(build.project, build.params, function(err) {
|
var executor = node.run(build.project, build.params, function(err) {
|
||||||
self._updateBuild(
|
self._updateBuild(
|
||||||
build,
|
build,
|
||||||
|
@ -7,7 +7,12 @@ var Distributor = require('../../lib/distributor').Distributor,
|
|||||||
Steppy = require('twostep').Steppy;
|
Steppy = require('twostep').Steppy;
|
||||||
|
|
||||||
|
|
||||||
describe('Distributor blocking', function() {
|
var expectStatus = function(spy, index, projectName, status) {
|
||||||
|
expect(spy.getCall(index).args[0].project.name).equal(projectName);
|
||||||
|
expect(spy.getCall(index).args[1].status).equal(status);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Distributor blocking with max 2 executors count', function() {
|
||||||
var distributor, updateBuildSpy, projects;
|
var distributor, updateBuildSpy, projects;
|
||||||
|
|
||||||
var nodes = [{type: 'local', maxExecutorsCount: 2}];
|
var nodes = [{type: 'local', maxExecutorsCount: 2}];
|
||||||
@ -18,15 +23,7 @@ describe('Distributor blocking', function() {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should no work when two non-blocking projects run', function() {
|
var itRunParallelProjects = function() {
|
||||||
before(function() {
|
|
||||||
projects = [{
|
|
||||||
name: 'project1',
|
|
||||||
}, {
|
|
||||||
name: 'project2'
|
|
||||||
}];
|
|
||||||
});
|
|
||||||
|
|
||||||
it('distributor should be created without errors', function() {
|
it('distributor should be created without errors', function() {
|
||||||
distributor = new Distributor({projects: projects, nodes: nodes});
|
distributor = new Distributor({projects: projects, nodes: nodes});
|
||||||
updateBuildSpy = sinon.spy(distributor, '_updateBuild');
|
updateBuildSpy = sinon.spy(distributor, '_updateBuild');
|
||||||
@ -47,32 +44,26 @@ describe('Distributor blocking', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('both projects should be queued', function() {
|
it('both projects should be queued', function() {
|
||||||
var spy = updateBuildSpy;
|
expectStatus(updateBuildSpy, 0, 'project1', 'queued');
|
||||||
expect(spy.getCall(0).args[0].project.name).equal('project1');
|
expectStatus(updateBuildSpy, 1, 'project2', 'queued');
|
||||||
expect(spy.getCall(0).args[1].status).equal('queued');
|
|
||||||
expect(spy.getCall(1).args[0].project.name).equal('project2');
|
|
||||||
expect(spy.getCall(1).args[1].status).equal('queued');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('both projects should be in-progress', function() {
|
it('both projects should be in-progress', function() {
|
||||||
var spy = updateBuildSpy;
|
expectStatus(updateBuildSpy, 2, 'project1', 'in-progress');
|
||||||
expect(spy.getCall(2).args[0].project.name).equal('project1');
|
expectStatus(updateBuildSpy, 3, 'project2', 'in-progress');
|
||||||
expect(spy.getCall(2).args[1].status).equal('in-progress');
|
|
||||||
expect(spy.getCall(3).args[0].project.name).equal('project2');
|
|
||||||
expect(spy.getCall(3).args[1].status).equal('in-progress');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should work project2 blocked by project1', function() {
|
it('both projects should be done', function() {
|
||||||
before(function() {
|
expectStatus(updateBuildSpy, 4, 'project1', 'done');
|
||||||
projects = [{
|
expectStatus(updateBuildSpy, 5, 'project2', 'done');
|
||||||
name: 'project1',
|
|
||||||
}, {
|
|
||||||
name: 'project2',
|
|
||||||
blockedBy: ['project1']
|
|
||||||
}];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('update build called 6 times totally', function() {
|
||||||
|
expect(updateBuildSpy.callCount).equal(6);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var itRunSequentialProjects = function() {
|
||||||
it('distributor should be created without errors', function() {
|
it('distributor should be created without errors', function() {
|
||||||
distributor = new Distributor({projects: projects, nodes: nodes});
|
distributor = new Distributor({projects: projects, nodes: nodes});
|
||||||
updateBuildSpy = sinon.spy(distributor, '_updateBuild');
|
updateBuildSpy = sinon.spy(distributor, '_updateBuild');
|
||||||
@ -93,17 +84,12 @@ describe('Distributor blocking', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('both projects should be queued', function() {
|
it('both projects should be queued', function() {
|
||||||
var spy = updateBuildSpy;
|
expectStatus(updateBuildSpy, 0, 'project1', 'queued');
|
||||||
expect(spy.getCall(0).args[0].project.name).equal('project1');
|
expectStatus(updateBuildSpy, 1, 'project2', 'queued');
|
||||||
expect(spy.getCall(0).args[1].status).equal('queued');
|
|
||||||
expect(spy.getCall(1).args[0].project.name).equal('project2');
|
|
||||||
expect(spy.getCall(1).args[1].status).equal('queued');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('project1 should be in-progress', function() {
|
it('project1 should be in-progress', function() {
|
||||||
var spy = updateBuildSpy;
|
expectStatus(updateBuildSpy, 2, 'project1', 'in-progress');
|
||||||
expect(spy.getCall(2).args[0].project.name).equal('project1');
|
|
||||||
expect(spy.getCall(2).args[1].status).equal('in-progress');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('project2 should have wait reason (project1)', function() {
|
it('project2 should have wait reason (project1)', function() {
|
||||||
@ -113,6 +99,78 @@ describe('Distributor blocking', function() {
|
|||||||
'Blocked by currently running "project1"'
|
'Blocked by currently running "project1"'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('project1 should be done', function() {
|
||||||
|
expectStatus(updateBuildSpy, 4, 'project1', 'done');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('project2 should be in-progress', function() {
|
||||||
|
expectStatus(updateBuildSpy, 5, 'project2', 'in-progress');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('project2 should be done', function() {
|
||||||
|
expectStatus(updateBuildSpy, 6, 'project2', 'done');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('update build called 7 times totally', function() {
|
||||||
|
expect(updateBuildSpy.callCount).equal(7);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('should run 2 non-blocking projects in parallel', function() {
|
||||||
|
before(function() {
|
||||||
|
projects = [{
|
||||||
|
name: 'project1',
|
||||||
|
}, {
|
||||||
|
name: 'project2'
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
|
itRunParallelProjects();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('should run project1, then 2, when 2 blocked by 1', function() {
|
||||||
|
before(function() {
|
||||||
|
projects = [{
|
||||||
|
name: 'project1',
|
||||||
|
}, {
|
||||||
|
name: 'project2',
|
||||||
|
blockedBy: ['project1']
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
|
itRunSequentialProjects();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('should run project1, then 2, when 1 blocks 2', function() {
|
||||||
|
before(function() {
|
||||||
|
projects = [{
|
||||||
|
name: 'project1',
|
||||||
|
blocks: ['project2']
|
||||||
|
}, {
|
||||||
|
name: 'project2'
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
|
itRunSequentialProjects();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe(
|
||||||
|
'should run 1, 2 in parallel, when 1 block 3, 2 blocked by 3',
|
||||||
|
function() {
|
||||||
|
before(function() {
|
||||||
|
projects = [{
|
||||||
|
name: 'project1',
|
||||||
|
blocks: ['project3']
|
||||||
|
}, {
|
||||||
|
name: 'project2',
|
||||||
|
blockedBy: ['project3']
|
||||||
|
}, {
|
||||||
|
name: 'project3'
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
|
itRunParallelProjects();
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user