1313import org .bson .Document ;
1414import org .junit .jupiter .api .AfterEach ;
1515import org .junit .jupiter .api .BeforeEach ;
16+ import org .junit .jupiter .api .Test ;
1617import org .junit .jupiter .params .ParameterizedClass ;
1718import org .junit .jupiter .params .provider .MethodSource ;
1819import org .slf4j .Logger ;
2627import works .bosk .drivers .mongo .PandoFormat ;
2728import works .bosk .exceptions .FlushFailureException ;
2829import works .bosk .exceptions .InvalidTypeException ;
29- import works .bosk .junit .InjectedTest ;
3030import works .bosk .testing .drivers .state .TestEntity ;
3131import works .bosk .testing .junit .Slow ;
3232
@@ -102,7 +102,7 @@ enum FlushOrWait {
102102 }
103103
104104
105- @ InjectedTest
105+ @ Test
106106 @ DisruptsMongoProxy
107107 void initialOutage_recovers () throws InvalidTypeException , InterruptedException , IOException {
108108 LOGGER .debug ("Set up the database contents to be different from initialRoot" );
@@ -163,20 +163,25 @@ private void waitFor(BoskDriver driver) throws IOException, InterruptedException
163163 break ;
164164 case WAIT :
165165 // The user really has no business expecting updates to occur promptly.
166- // Because this is sometimes used when the bosk is (deliberately)
167- // malfunctioning, we should wait much longer than the recovery time.
168166 //
169- // Unfortunately, this makes these tests inevitably slow.
167+ // This is used in two circumstances:
168+ // 1. If the operation is expected to succeed, then the worst-case
169+ // delay is the delay time for the connection loop, plus the time
170+ // to detect and publish the new format driver,
171+ // plus the time to execute the operation itself.
172+ // 4*timescaleMS ought to be plenty for all that.
173+ // 2. If the operation is expected to fail, no amount of waiting
174+ // will make it succeed, so we can ignore this case.
170175 //
171- long sleepTime = 12L * driverSettings .timescaleMS ();
176+ long sleepTime = 4L * driverSettings .timescaleMS ();
172177 LOGGER .debug ("Waiting for {} ms" , sleepTime );
173178 Thread .sleep (sleepTime );
174179 LOGGER .debug ("...done waiting" );
175180 break ;
176181 }
177182 }
178183
179- @ InjectedTest
184+ @ Test
180185 void databaseDropped_recovers () throws InterruptedException , IOException {
181186 testRecovery (() -> {
182187 LOGGER .debug ("Drop database" );
@@ -187,7 +192,7 @@ void databaseDropped_recovers() throws InterruptedException, IOException {
187192 }, (_ ) -> initializeDatabase ("after drop" ));
188193 }
189194
190- @ InjectedTest
195+ @ Test
191196 void collectionDropped_recovers () throws InterruptedException , IOException {
192197 testRecovery (() -> {
193198 LOGGER .debug ("Drop collection" );
@@ -198,7 +203,7 @@ void collectionDropped_recovers() throws InterruptedException, IOException {
198203 }, (_ ) -> initializeDatabase ("after drop" ));
199204 }
200205
201- @ InjectedTest
206+ @ Test
202207 void documentDeleted_recovers () throws InterruptedException , IOException {
203208 testRecovery (() -> {
204209 LOGGER .debug ("Delete document" );
@@ -209,7 +214,7 @@ void documentDeleted_recovers() throws InterruptedException, IOException {
209214 }, (_ ) -> initializeDatabase ("after deletion" ));
210215 }
211216
212- @ InjectedTest
217+ @ Test
213218 void documentReappears_recovers () throws InterruptedException , IOException {
214219 MongoCollection <Document > collection = mongoService .client ()
215220 .getDatabase (driverSettings .database ())
@@ -236,7 +241,7 @@ void documentReappears_recovers() throws InterruptedException, IOException {
236241 });
237242 }
238243
239- @ InjectedTest
244+ @ Test
240245 void revisionDeleted_recovers () throws InterruptedException , IOException {
241246 // It's not clear that this is a valid test. If this test is a burden to support,
242247 // we can consider removing it.
@@ -322,6 +327,12 @@ private void testRecovery(Runnable disruptiveAction, Function<TestEntity, TestEn
322327
323328 Bosk <TestEntity > bosk = new Bosk <>(boskName (getClass ().getSimpleName ()), TestEntity .class , AbstractMongoDriverTest ::initialRoot , BoskConfig .<TestEntity >builder ().driverFactory (driverFactory ).build ());
324329
330+ // With short timescales or slow networks, the bosk initial state
331+ // can time out trying to read the database and instead uses AbstractMongoDriverTest::initialRoot.
332+ // This is actually valid behaviour for a sufficiently impatient user.
333+ // Let's wait first to ensure we have the state from the database.
334+ waitFor (bosk .driver ());
335+
325336 try (var _ = bosk .readContext ()) {
326337 // Note: with very short timescales, this assertion can fail because the newly created bosk
327338 // times out trying to read the database contents and instead uses AbstractMongoDriverTest::initialRoot.
0 commit comments