@@ -4085,6 +4085,51 @@ void asynchronousUpdateModeStatusTransitions() throws Exception {
40854085 gav .drop ();
40864086 }
40874087
4088+ /**
4089+ * Regression stress test for the awaitReady race: between rebuilds, the worker resets
4090+ * asyncRebuildNeeded=false a moment before flipping status to BUILDING. A reader doing
4091+ * the two volatile reads non-atomically can see status=READY together with
4092+ * asyncRebuildNeeded=false and return early on a stale snapshot. Many iterations of
4093+ * rapid-fire commits widen the window enough to fail consistently.
4094+ */
4095+ @ Test
4096+ void asynchronousUpdateModeAwaitReadyConvergesAfterRapidCommits () throws Exception {
4097+ database .getSchema ().createVertexType ("Person" );
4098+ database .getSchema ().createEdgeType ("FOLLOWS" );
4099+
4100+ database .begin ();
4101+ final MutableVertex alice = database .newVertex ("Person" ).set ("name" , "Alice" ).save ();
4102+ database .commit ();
4103+
4104+ final GraphAnalyticalView gav = GraphAnalyticalView .builder (database )
4105+ .withName ("async-stress" )
4106+ .withVertexTypes ("Person" )
4107+ .withEdgeTypes ("FOLLOWS" )
4108+ .withUpdateMode (GraphAnalyticalView .UpdateMode .ASYNCHRONOUS )
4109+ .build ();
4110+
4111+ final int iterations = 50 ;
4112+ final int commitsPerIteration = 5 ;
4113+ int expectedNodeCount = 1 ; // Alice
4114+ int expectedEdgeCount = 0 ;
4115+ for (int it = 0 ; it < iterations ; it ++) {
4116+ for (int i = 0 ; i < commitsPerIteration ; i ++) {
4117+ database .begin ();
4118+ final MutableVertex v = database .newVertex ("Person" ).set ("name" , "P" + it + "_" + i ).save ();
4119+ alice .newEdge ("FOLLOWS" , v );
4120+ database .commit ();
4121+ expectedNodeCount ++;
4122+ expectedEdgeCount ++;
4123+ }
4124+
4125+ assertThat (gav .awaitReady (10 , TimeUnit .SECONDS )).as ("iteration %d" , it ).isTrue ();
4126+ assertThat (gav .getNodeCount ()).as ("nodeCount after iteration %d" , it ).isEqualTo (expectedNodeCount );
4127+ assertThat (gav .getEdgeCount ()).as ("edgeCount after iteration %d" , it ).isEqualTo (expectedEdgeCount );
4128+ }
4129+
4130+ gav .drop ();
4131+ }
4132+
40884133 // ---- GAVExpandInto tests ----
40894134
40904135 @ Test
0 commit comments