Skip to content

Commit ae75a07

Browse files
committed
update tests code post bumps
1 parent 3c902fe commit ae75a07

38 files changed

+132
-140
lines changed

tests/functional/client/testClientConnections.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ describe('Client connections', async function test() {
7373
Object.entries(expected).forEach(([k, v]) => {
7474
assert.strictEqual(data[0][k], v);
7575
});
76+
return done();
7677
});
7778
};
7879

@@ -112,27 +113,37 @@ describe('Client connections', async function test() {
112113
}
113114
assert.strictEqual(res, 'OK');
114115

115-
// Requests made with async.times will stay open when they occur
116-
// during the failover window so and async.race is used to resolve
117-
async.race([
118-
() => setTimeout(() => this.loadgen.emit('finished'), 3000),
119-
() => async.times(
120-
100,
121-
() => makeRequest(this, done),
122-
() => this.loadgen.emit('finished'),
123-
),
116+
return async.race([
117+
cb => {
118+
setTimeout(() => {
119+
this.loadgen.emit('finished');
120+
cb();
121+
}, 3000);
122+
return undefined;
123+
},
124+
cb => {
125+
async.times(
126+
100,
127+
(n, next) => makeRequest(this, next),
128+
err => {
129+
if (err) {return cb(err);}
130+
this.loadgen.emit('finished');
131+
return cb();
132+
},
133+
);
134+
return undefined;
135+
},
124136
]);
125137
});
126138

127-
sentinelSub.on('message', (chan, message) => {
128-
// wait until the old master is added as a replica so any stale connections would be transfered
139+
// Add return statement here
140+
return sentinelSub.once('message', (chan, message) => {
129141
assert.strictEqual(chan, '+slave');
130-
// checks that ports differ between old and new master
131142
const data = message.split(' ');
132143
const [oldPort, newPort] = [data[3], data[7]];
133144
assert.notStrictEqual(oldPort, newPort);
134145

135-
return this.loadgen.on('finished', () => {
146+
return this.loadgen.once('finished', () => {
136147
assert(this.requestsDuringFailover > 1);
137148
return done();
138149
});

tests/functional/hardLimit/testHardLimit.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const assert = require('assert');
22
const fs = require('fs');
33
const sinon = require('sinon');
4-
const uuid = require('uuid');
4+
const { v4: uuid } = require('uuid');
55
const promClient = require('prom-client');
66

77
const { clients: warp10Clients } = require('../../../libV2/warp10');
@@ -10,14 +10,13 @@ const { MonitorDiskUsage } = require('../../../libV2/tasks');
1010
const { fillDir } = require('../../utils/v2Data');
1111
const { assertMetricValue } = require('../../utils/prom');
1212

13-
// eslint-disable-next-line func-names
1413
describe('Test MonitorDiskUsage hard limit', function () {
1514
this.timeout(30000);
1615
let task;
1716
let path;
1817

1918
beforeEach(async () => {
20-
path = `/tmp/diskusage-${uuid.v4()}`;
19+
path = `/tmp/diskusage-${uuid()}`;
2120
fs.mkdirSync(`${path}/datalog`, { recursive: true });
2221
promClient.register.clear();
2322
task = new MonitorDiskUsage({ warp10: warp10Clients, enableMetrics: true });

tests/functional/interval/testInterval.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const assert = require('assert');
22
const async = require('async');
3-
const uuid = require('uuid/v4');
3+
const { v4: uuid } = require('uuid');
44

55
const UtapiClient = require('../../../lib/UtapiClient');
66
const mock = require('../../utils/mock');

tests/functional/server/testInvalidRequests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('Invalid requests', () => {
1818
{
1919
describe: 'should forbid a GET request ',
2020
header: {
21-
host: 'localhost',
21+
host: '127.0.0.1',
2222
port: 8100,
2323
method: 'GET',
2424
service: 's3',
@@ -30,7 +30,7 @@ describe('Invalid requests', () => {
3030
{
3131
describe: 'should forbid a GET request ',
3232
header: {
33-
host: 'localhost',
33+
host: '127.0.0.1',
3434
port: 8100,
3535
method: 'GET',
3636
service: 's3',

tests/functional/softLimit/testSoftLimit.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const { expirationChunkDuration } = require('../../../libV2/constants');
99

1010
const { fetchRecords } = require('../../utils/v2Data');
1111

12-
// eslint-disable-next-line func-names
1312
describe('Test MonitorDiskUsage soft limit', function () {
1413
this.timeout(30000);
1514
let task;

tests/functional/v2/cache/testRedisBackend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const assert = require('assert');
2-
const uuid = require('uuid');
2+
const { v4: uuid } = require('uuid');
33
const { RedisCache } = require('../../../../libV2/cache').backends;
44
const { shardFromTimestamp } = require('../../../../libV2/utils');
55
const schema = require('../../../../libV2/cache/schema');
@@ -13,7 +13,7 @@ describe('Test cache redis backend', () => {
1313
let cache;
1414
let prefix;
1515
beforeEach(async () => {
16-
prefix = uuid.v4();
16+
prefix = uuid();
1717
cache = new RedisCache({}, prefix);
1818
return cache.connect();
1919
});

tests/functional/v2/server/testGetStorage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const assert = require('assert');
22
const async = require('async');
3-
const uuid = require('uuid');
3+
const { v4: uuid } = require('uuid');
44

55
const UtapiClient = require('../../../../libV2/client');
66
const { clients: warp10Clients } = require('../../../../libV2/warp10');
@@ -22,7 +22,7 @@ const getClient = () => new CacheClient({
2222

2323
const warp10 = warp10Clients[0];
2424

25-
// eslint-disable-next-line func-names
25+
2626
describe('Test getStorage handler', function () {
2727
this.timeout(120000);
2828
let client;
@@ -40,7 +40,7 @@ describe('Test getStorage handler', function () {
4040

4141
const { events: _events, totals: _totals } = generateCustomEvents(
4242
now() - (120 * 1000000), now() - (30 * 1000000), 50, {
43-
[uuid.v4()]: { [uuid.v4()]: [uuid.v4()] },
43+
[uuid()]: { [uuid()]: [uuid()] },
4444
},
4545
);
4646
events = _events;
@@ -122,7 +122,7 @@ describe('Test getStorage handler', function () {
122122
});
123123

124124
it('should return a 0 instead of a negative value', async () => {
125-
const account = `imaaccount-${uuid.v4()}`;
125+
const account = `imaaccount-${uuid()}`;
126126
const event = new UtapiMetric({
127127
timestamp: now(),
128128
account,

tests/functional/v2/server/testHealthcheck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const needle = require('needle');
44

55
describe('Test healthcheck handler', () => {
66
it('should return true', async () => {
7-
const res = await needle('get', 'http://localhost:8100/_/healthcheck');
7+
const res = await needle('get', 'http://127.0.0.1:8100/_/healthcheck');
88
assert.strictEqual(res.statusCode, 200);
99
assert.strictEqual(res.statusMessage, 'OK');
1010
});

tests/functional/v2/server/testIngestMetric.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { generateFakeEvents } = require('../../../utils/v2Data');
66
function utapiRequest(events) {
77
return needle(
88
'post',
9-
'http://localhost:8100/v2/ingest',
9+
'http://127.0.0.1:8100/v2/ingest',
1010
events,
1111
);
1212
}

tests/functional/v2/server/testListMetrics.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/* eslint-disable func-names */
21
const assert = require('assert');
32
const needle = require('needle');
4-
const uuid = require('uuid');
3+
const { v4: uuid } = require('uuid');
54
const aws4 = require('aws4');
65

76
const { clients: warp10Clients } = require('../../../../libV2/warp10');
@@ -41,7 +40,7 @@ async function listMetrics(level, resources, start, end, credentials) {
4140
}
4241

4342
const headers = {
44-
host: 'localhost',
43+
host: '127.0.0.1',
4544
port: 8100,
4645
method: 'POST',
4746
service: 's3',
@@ -58,10 +57,9 @@ async function listMetrics(level, resources, start, end, credentials) {
5857
};
5958

6059
const sig = aws4.sign(headers, _credentials);
61-
6260
return needle(
6361
'post',
64-
`http://localhost:8100/${level}?Action=ListMetrics`,
62+
`http://127.0.0.1:8100/${level}?Action=ListMetrics`,
6563

6664
body,
6765
{
@@ -101,15 +99,15 @@ describe('Test listMetric', function () {
10199
let otherUser;
102100
let serviceAccount;
103101
let serviceUser;
104-
const bucket = uuid.v4();
105-
const otherBucket = uuid.v4();
102+
const bucket = uuid();
103+
const otherBucket = uuid();
106104
let totals;
107105

108106
before(async () => {
109-
account = await vaultclient.createAccountAndKeys(uuid.v4());
110-
user = await vaultclient.createUserAndKeys(account, uuid.v4());
111-
otherAccount = await vaultclient.createAccountAndKeys(uuid.v4());
112-
otherUser = await vaultclient.createUser(otherAccount, uuid.v4());
107+
account = await vaultclient.createAccountAndKeys(uuid());
108+
user = await vaultclient.createUserAndKeys(account, uuid());
109+
otherAccount = await vaultclient.createAccountAndKeys(uuid());
110+
otherUser = await vaultclient.createUser(otherAccount, uuid());
113111
serviceAccount = await vaultclient.createInternalServiceAccountAndKeys();
114112
serviceUser = await vaultclient.ensureServiceUser(serviceAccount);
115113

tests/functional/v2/server/testPrometheusMetrics.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const testMetrics = async pair => {
1515

1616
describe('Test Prometheus Metrics', () => {
1717
const nameUrlPairs = [
18-
['utapi nodejs service exporter', 'http://localhost:8100/_/metrics'],
19-
['sensision exporter', 'http://localhost:9718/metrics'],
20-
['redis exporter', 'http://localhost:9121/metrics'],
18+
['utapi nodejs service exporter', 'http://127.0.0.1:8100/_/metrics'],
19+
['sensision exporter', 'http://127.0.0.1:9718/metrics'],
20+
['redis exporter', 'http://127.0.0.1:9121/metrics'],
2121
];
2222
nameUrlPairs.forEach(pair => testMetrics(pair));
2323
});

tests/functional/v2/task/testBaseTask.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const { getMetricValues } = require('../../../utils/prom');
1111

1212
const METRICS_SERVER_PORT = 10999;
1313

14-
class CustomTask extends BaseTask {
15-
// eslint-disable-next-line class-methods-use-this
14+
class CustomTask extends BaseTask {
1615
_registerMetricHandlers() {
1716
const foo = new promClient.Gauge({
1817
name: 's3_utapi_custom_task_foo_total',
@@ -48,7 +47,7 @@ describe('Test BaseTask metrics', () => {
4847
it('should start a metrics server on the provided port', async () => {
4948
const res = await needle(
5049
'get',
51-
`http://localhost:${METRICS_SERVER_PORT}${DEFAULT_METRICS_ROUTE}`,
50+
`http://127.0.0.1:${METRICS_SERVER_PORT}${DEFAULT_METRICS_ROUTE}`,
5251
);
5352
const lines = res.body.split('\n');
5453
const first = lines[0];

tests/functional/v2/task/testCreateCheckpoint.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const assert = require('assert');
22
const promClient = require('prom-client');
3-
const uuid = require('uuid');
3+
const { v4: uuid } = require('uuid');
44

55
const { Warp10Client } = require('../../../../libV2/warp10');
66
const { convertTimestamp } = require('../../../../libV2/utils');
@@ -39,7 +39,7 @@ function assertResults(totals, series) {
3939
});
4040
}
4141

42-
// eslint-disable-next-line func-names
42+
4343
describe('Test CreateCheckpoint', function () {
4444
this.timeout(10000);
4545

@@ -48,7 +48,7 @@ describe('Test CreateCheckpoint', function () {
4848
let checkpointTask;
4949

5050
beforeEach(async () => {
51-
prefix = uuid.v4();
51+
prefix = uuid();
5252

5353
warp10 = new Warp10Client({ nodeId: prefix });
5454
checkpointTask = new CreateCheckpoint({ warp10: [warp10], enableMetrics: true });
@@ -65,7 +65,7 @@ describe('Test CreateCheckpoint', function () {
6565
const start = getTs(-300);
6666
const stop = getTs(-120);
6767
const { events, totals } = generateCustomEvents(start, stop, 100,
68-
{ [uuid.v4()]: { [uuid.v4()]: [uuid.v4()] } });
68+
{ [uuid()]: { [uuid()]: [uuid()] } });
6969

7070
await warp10.ingest({ className: 'utapi.event' }, events);
7171
await checkpointTask._execute(getTs(0));
@@ -84,7 +84,7 @@ describe('Test CreateCheckpoint', function () {
8484
});
8585

8686
it('should only include events not in an existing checkpoint', async () => {
87-
const accounts = { [uuid.v4()]: { [uuid.v4()]: [uuid.v4()] } };
87+
const accounts = { [uuid()]: { [uuid()]: [uuid()] } };
8888

8989
const { events: historicalEvents } = generateCustomEvents(
9090
getTs(-500),
@@ -121,7 +121,7 @@ describe('Test CreateCheckpoint', function () {
121121
getTs(-300),
122122
getTs(-120),
123123
100,
124-
{ [uuid.v4()]: { [uuid.v4()]: [uuid.v4()] } },
124+
{ [uuid()]: { [uuid()]: [uuid()] } },
125125
);
126126

127127
await warp10.ingest({ className: 'utapi.event' }, events);
@@ -142,6 +142,6 @@ describe('Test CreateCheckpoint', function () {
142142
className: 'utapi.checkpoint', labels: { node: prefix }, start: getTs(1), stop: 10 * 1000 * 1000,
143143
});
144144

145-
assert.strictEqual(JSON.parse(results.result[0]).length, 0);
145+
assert.strictEqual(results.result.length, 0);
146146
});
147147
});

0 commit comments

Comments
 (0)