Skip to content

Commit

Permalink
fix bad requests causing unit tests to hang (#478)
Browse files Browse the repository at this point in the history
* fix hanging requests

* change mocha to 3.5.2

* add --no-exit tag to unit tests

* unref diskretry timeout to prevent blocking app from terminating
  • Loading branch information
markwolff committed Jan 23, 2019
1 parent 7953d1b commit 369b91d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Library/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Sender {
if (this._enableDiskRetryMode) {
// try to send any cached events if the user is back online
if (res.statusCode === 200) {
setTimeout(() => this._sendFirstFileOnDisk(), this._resendInterval);
setTimeout(() => this._sendFirstFileOnDisk(), this._resendInterval).unref();
// store to disk in case of burst throttling
} else if (
res.statusCode === 408 || // Timeout
Expand Down
2 changes: 1 addition & 1 deletion Tests/EndToEnd.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CorrelationContextManager } from "../AutoCollection/CorrelationContextM
class fakeResponse {
private callbacks: { [event: string]: (data?: any) => void } = Object.create(null);
public setEncoding(): void { };
public statusCode: number;
public statusCode: number = 200;

constructor(private passImmediately: boolean = true) { }

Expand Down
10 changes: 10 additions & 0 deletions Tests/Library/Config.tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import assert = require("assert");
import sinon = require("sinon");
var http = require("http");
var https = require("https");

import Config = require("../../Library/Config");

Expand All @@ -9,6 +11,14 @@ describe("Library/Config", () => {
var appVer = "appVer";

describe("#constructor(iKey)", () => {
beforeEach(()=> {
sinon.stub(http, 'request');
sinon.stub(https, 'request');
});
afterEach(() => {
http.request.restore();
https.request.restore();
})
it("should throw if no iKey is available", () => {
var env = {};
var originalEnv = process.env;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Library/Util.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ describe("Library/Util", () => {
if (process.env.hasOwnProperty('no_proxy')) {
delete process.env.no_proxy;
}
sinon.spy(http, 'request');
sinon.spy(https, 'request');
sinon.stub(http, 'request');
sinon.stub(https, 'request');
});

afterEach(() => {
Expand Down
77 changes: 42 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@
"prepublishOnly": "npm run build",
"pretest": "npm run build",
"test": "npm run test:ts && npm run test:js",
"test:ts": "mocha ./out/Tests --recursive",
"test:js": "mocha ./Tests/js --recursive",
"test:ts": "mocha ./out/Tests --recursive --no-exit",
"test:js": "mocha ./Tests/js --recursive --no-exit",
"functionaltest": "npm run build && npm pack && node --use_strict ./Tests/FunctionalTests/RunFunctionalTests.js",
"backcompattest": "npm run build && npm pack && node --use_strict ./Tests/BackCompatibility/RunBackCompatTests.js"
},
"devDependencies": {
"@types/cls-hooked": "^4.2.1",
"@types/mocha": "2.2.40",
"@types/mocha": "2.2.48",
"@types/node": "4.2.4",
"@types/sinon": "2.1.2",
"typescript": "2.4.2",
"mocha": "3.1.2",
"mocha": "3.5.2",
"node-mocks-http": "1.2.3",
"sinon": "1.17.6"
},
Expand Down

0 comments on commit 369b91d

Please sign in to comment.