Skip to content

Commit 8a3627b

Browse files
committed
Improve MongoDriverRecoveryTest
1 parent b7817a3 commit 8a3627b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

bosk-mongo/src/test/java/works/bosk/drivers/mongo/internal/MongoDriverRecoveryTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ enum FlushOrWait {
102102
}
103103

104104

105+
@Slow // Takes 14*timescale for FLUSH and 44*timescale for WAIT
105106
@InjectedTest
106107
@DisruptsMongoProxy
107108
void initialOutage_recovers() throws InvalidTypeException, InterruptedException, IOException {
@@ -114,6 +115,7 @@ void initialOutage_recovers() throws InvalidTypeException, InterruptedException,
114115

115116
LOGGER.debug("Create a new bosk that can't connect");
116117
Bosk<TestEntity> bosk = new Bosk<>(getClass().getSimpleName() + boskCounter.incrementAndGet(), TestEntity.class, AbstractMongoDriverTest::initialRoot, BoskConfig.<TestEntity>builder().driverFactory(driverFactory).build());
118+
LOGGER.debug("Done creating bosk");
117119

118120
MongoDriverSpecialTest.Refs refs = bosk.buildReferences(MongoDriverSpecialTest.Refs.class);
119121
BoskDriver driver = bosk.driver();
@@ -133,7 +135,9 @@ void initialOutage_recovers() throws InvalidTypeException, InterruptedException,
133135
LOGGER.debug("Restore mongo connection");
134136
mongoService.restoreConnection();
135137

136-
LOGGER.debug("Flush and check that the state updates");
138+
LOGGER.debug("Wait and check that the state updates");
139+
// With FLUSH this succeeds almost immediately.
140+
// With WAIT it is artificially delayed.
137141
waitFor(driver);
138142
try (var _ = bosk.readContext()) {
139143
assertEquals(initialState, bosk.rootReference().value(),
@@ -160,13 +164,16 @@ private void waitFor(BoskDriver driver) throws IOException, InterruptedException
160164
break;
161165
case WAIT:
162166
// The user really has no business expecting updates to occur promptly.
163-
// Let's wait several times the timescale so that the test
164-
// can set a short timescale to make FLUSH fast without risking
165-
// failures in the WAIT tests.
167+
// Because this is sometimes used when the bosk is (deliberately)
168+
// malfunctioning, we should wait much longer than the recovery time,
169+
// which (as I write this) is 5*timescale.
166170
//
167171
// Unfortunately, this makes these tests inevitably slow.
168172
//
169-
Thread.sleep(10L * driverSettings.timescaleMS());
173+
long sleepTime = 10L * driverSettings.timescaleMS();
174+
LOGGER.debug("Waiting for {} ms", sleepTime);
175+
Thread.sleep(sleepTime);
176+
LOGGER.debug("...done waiting");
170177
break;
171178
}
172179
}

0 commit comments

Comments
 (0)