Skip to content
This repository was archived by the owner on Feb 18, 2021. It is now read-only.

Commit 793d546

Browse files
author
Joshua T Corbin
committed
test/peer-churn: plant each turnip as soon as possible
1 parent 4bd33a9 commit 793d546

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

test/peer-churn.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var CountedReadySignal = require('ready-signal/counted');
2525
var timers = require('timers');
2626
var util = require('util');
2727

28+
var Turnip = require('./lib/turnip').Turnip;
2829
var Turnips = require('./lib/turnip').Turnips;
2930
var allocCluster = require('./lib/test-cluster.js');
3031
var CollapsedAssert = require('./lib/collapsed-assert.js');
@@ -130,22 +131,49 @@ allocCluster.test('peer churn', {
130131

131132
function thenShutdownFirstRound() {
132133
assert.comment('- thenShutdownFirstRound');
134+
135+
turnips = new Turnips();
136+
turnips.ready = new CountedReadySignal(first.length);
137+
133138
collectParallel(first, function each(remote, i, done) {
139+
var hostPort = remote.channel.hostPort;
140+
var parts = hostPort.split(':');
141+
var host = parts[0];
142+
var port = parseInt(parts[1], 10);
143+
134144
// half of them do an unad then destroy, the other half just go away
135145
if (i % 2 === 0) {
136146
remote.doUnregister(function unreged(err) {
137147
assert.ifError(err, 'expected no unregister error');
138-
remote.destroy(done);
148+
remote.destroy(plant);
139149
});
140150
} else {
141-
remote.destroy(done);
151+
remote.destroy(plant);
152+
}
153+
154+
function plant() {
155+
assert.comment('-- planting turnip[' + i + '] on ' + hostPort);
156+
turnips.turnips[i] = new Turnip(port, host, ready);
157+
done();
158+
}
159+
160+
function ready(err) {
161+
assert.comment('-- turnip[' + i + '] ready on ' + hostPort);
162+
assert.ifError(err, 'no unexpected turnip error');
163+
turnips.ready.signal();
142164
}
143165
}, thenWaitForReaper);
144166
}
145167

146168
function thenWaitForReaper() {
147169
assert.comment('- thenWaitForReaper');
148170

171+
timers.setTimeout(thenTurnip, fuzzedPeriods(SETTLE_PERIODS));
172+
}
173+
174+
function thenTurnip() {
175+
assert.comment('- thenTurnip');
176+
149177
checkAllLogs(cluster, assert, function checkEachLog(record) {
150178
assert.ok([
151179
// TODO: this is a bug parlayed into a warning
@@ -164,20 +192,8 @@ allocCluster.test('peer churn', {
164192
'draining peer',
165193
'implementing affinity change',
166194
'stopping peer drain',
167-
'pruning peers'
168-
].indexOf(record.msg) >= 0, 'expected reaping logs');
169-
});
170-
171-
timers.setTimeout(thenTurnip, fuzzedPeriods(SETTLE_PERIODS));
172-
}
173-
174-
function thenTurnip() {
175-
assert.comment('- thenTurnip');
195+
'pruning peers',
176196

177-
// checkNoLogs('reap', cluster, assert);
178-
179-
checkAllLogs(cluster, assert, function checkEachLog(record) {
180-
assert.ok([
181197
// these happen more for the peers that didn't unad above
182198
'connecting peers',
183199
'resetting connection',
@@ -188,12 +204,7 @@ allocCluster.test('peer churn', {
188204
].indexOf(record.msg) >= 0, 'expected peer churn logs');
189205
});
190206

191-
turnips = Turnips.forAll(first, function getRemotePortHost(remote) {
192-
var parts = remote.channel.hostPort.split(':');
193-
var host = parts[0];
194-
var port = parseInt(parts[1], 10);
195-
return [port, host];
196-
}, thenWaitAndSee);
207+
turnips.ready(thenWaitAndSee);
197208
}
198209

199210
function thenWaitAndSee() {

0 commit comments

Comments
 (0)