-
Notifications
You must be signed in to change notification settings - Fork 77
clean up unit-test errors when it timeouts #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| workflowApiService.workflowsGetGraphsByName = this.sandbox.stub(), | ||
| workflowApiService.defineTaskGraph = this.sandbox.stub(), | ||
| workflowApiService.destroyGraphDefinition = this.sandbox.stub() | ||
| arpCache.getCurrent = this.sandbox.stub().resolves([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.
| workflowApiService.getGraphDefinitions = this.sandbox.stub(), | ||
| workflowApiService.workflowsGetGraphsByName = this.sandbox.stub(), | ||
| workflowApiService.defineTaskGraph = this.sandbox.stub(), | ||
| workflowApiService.destroyGraphDefinition = this.sandbox.stub() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.
| return helper.startServer(overrides, endpointOpt); | ||
| }); | ||
|
|
||
| beforeEach(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since on-core helper.js has already create the sandbox, my suggestion is directly calling on-core's before (https://github.com/RackHD/on-core/blob/master/spec/helper.js#L268) rather than writing some duplicated code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your idea is calling
helper.before();
helper.httpServerBefore();
instead of
helper.httpServerBefore();
But we don't need helper.start in on-http, so none of the unit test files calls helper.before.
| }; | ||
|
|
||
| helper.httpServerAfter = function() { | ||
| after('helper.httpServer.after', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving this to httpServerBefore, so that the unit-test doesn't need to call the httpServerAfter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't make sense here if we want to insert an after block before helper.httpServer.after.
E.g.:
after(function() {
//call something
});
helper.httpServerAfter();
spec/lib/api/2.0/config-spec.js
Outdated
| afterEach('tear down mocks', function () { | ||
| configuration.set.reset(); | ||
| configuration.getAll.reset(); | ||
| helper.httpServerBefore([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to remove the argument [], since an empty array seems redundant
2fb94e2 to
44e16d4
Compare
44e16d4 to
ff4e602
Compare
ff4e602 to
e7a6192
Compare
spec/lib/api/2.0/ibms-spec.js
Outdated
| } | ||
| before(function () { | ||
| waterline = helper.injector.get('Services.Waterline'); | ||
| Errors = helper.injector.get('Errors');helper.injector.get("Services.Configuration"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose of 'helper.injector.get("Services.Configuration");'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good finding, it's not my purpose here. It's from the original code, and I think we should delete it.
|
@lanchongyizu Could you help post the errors in the RAC or in this PR's message? I see lots of minor changes which is not related to exception handler and this PR's topic |
spec/helper.js
Outdated
|
|
||
| helper.httpServerBefore = function(overrides, endpointOpt) { | ||
| before('helper.httpServer.before', function() { | ||
| this.timeout(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that some cases are setting timeout to 10000ms previously, if all are set to 5000ms, is it sure that it doesn't have random issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, they might include other tasks, so it was set to 10000ms, but here we just start HTTP server, so it is all set to 5000ms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After group discussion, it will be set to 10000ms.
e7a6192 to
ef1f66c
Compare
|
BUILD on-http #359 : FAILURE BUILD on-http #359 Error Logs ▼Test Name: Redfish Systems Root should return a valid Redfish storage list Error Details: expected 200 "OK", got 500 "Internal Server Error" Response body: { error: { code: 'Base.1.0.GeneralError', message: 'A general error has occurred. See ExtendedInfo for more information.', '@Message.ExtendedInfo': [ [Object], [Object] ] } } Error: expected 200 "OK", got 500 "Internal Server Error" at Test._assertStatus (/home/jenkins/workspace/on-http/build-deps/on-http/node_modules/supertest/lib/test.js:232:12) at Test._assertFunction (/home/jenkins/workspace/on-http/build-deps/on-http/node_modules/supertest/lib/test.js:247:11) at Test.assert (/home/jenkins/workspace/on-http/build-deps/on-http/node_modules/supertest/lib/test.js:148:18) at assert (/home/jenkins/workspace/on-http/build-deps/on-http/node_modules/supertest/lib/test.js:127:12) at /home/jenkins/workspace/on-http/build-deps/on-http/node_modules/supertest/lib/test.js:124:5 at Test.Request.callback (/home/jenkins/workspace/on-http/build-deps/on-http/node_modules/supertest/node_modules/superagent/lib/node/index.js:703:3) at IncomingMessage.<anonymous> (/home/jenkins/workspace/on-http/build-deps/on-http/node_modules/supertest/node_modules/superagent/lib/node/index.js:922:12) at emitNone (events.js:72:20) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:923:12) at nextTickCallbackWith2Args (node.js:458:9) at process._tickDomainCallback (node.js:413:17) Stack Trace: Error: expected 200 "OK", got 500 "Internal Server Error" at Test._assertStatus (node_modules/supertest/lib/test.js:232:12) at Test._assertFunction (node_modules/supertest/lib/test.js:247:11) at Test.assert (node_modules/supertest/lib/test.js:148:18) at assert (node_modules/supertest/lib/test.js:127:12) at node_modules/supertest/lib/test.js:124:5 at Test.Request.callback (node_modules/supertest/node_modules/superagent/lib/node/index.js:703:3) at IncomingMessage.<anonymous> (node_modules/supertest/node_modules/superagent/lib/node/index.js:922:12) at endReadableNT (_stream_readable.js:923:12) |
|
The main errors are in SH sandbox Jenkins, such as http://10.62.59.175:8080/blue/organizations/jenkins/on-core_jamie/detail/on-core_jamie/29/tests |
711a66a to
33b6a09
Compare
|
BUILD on-http #368 : FAILURE |
33b6a09 to
f69b016
Compare
| Errors = helper.injector.get('Errors'); | ||
| waterline = helper.injector.get('Services.Waterline'); | ||
| return helper.injector.get('Views').load(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see two "before" here after this modification. Will they be called by parallel? If yes, as the previous code is a promise chain, will this change bring any race condition during the initialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, they are called one by one.
|
|
||
| helper.stopServer = function () { | ||
| return helper.injector.get('app').stop(); | ||
| if (helper.injector) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious about the case when helper.injector is null, since all the logic in https://github.com/RackHD/on-core/blob/master/spec/helper.js#L123 looks synchronized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could imagine that some unhandled exceptions are thrown before https://github.com/RackHD/on-core/blob/master/spec/helper.js#L163, then mocha will go on with the after section, then helper.injector would be undefined.
| waterline = helper.injector.get('Services.Waterline'); | ||
| waterline.localusers = { | ||
| findOne: sinon.stub() | ||
| findOne: sandbox.stub() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to use "this.sandbox" here to align with other files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this specific file, it defines its own sandbox, so we keep it here. And before section doesn't have this.sandbox, which only exists in beforeEach section.
| before('start HTTP server', function () { | ||
| this.timeout(5000); | ||
|
|
||
| before(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this before be combined with this one https://github.com/RackHD/on-http/pull/697/files#diff-cf0f2855402ebeda8abc6126044353caR54 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, this is to stub redfishTool before httpServer is started, so we can't combine these two before section.
1) add helper.httpServerBefore and helper.httpServerAfter as common methods to start and stop mock HTTP server. 2) fix the issue that some unit test file doesn't stop mock HTTP server when starting mock server timeouts. 3) add global sandbox in beforeEach, and restore it in afterEach 4) remove unnecessary resetStubs and restoreStubs
f69b016 to
2e91df5
Compare
Backgroud
This is for the story https://rackhd.atlassian.net/browse/RAC-5639.
During work of https://rackhd.atlassian.net/browse/RAC-5593, we found many unit test cases won't do the clean-up work if running into failure (aka exception handler) , so the plan is to add clean-up work in unit test cases.
DONE
methods to start and stop mock HTTP server.
when starting mock server timeouts.
TEST
It's tested in sandbox:
http://10.62.59.175:8080/job/on-core_jamie/
@RackHD/corecommitters