Skip to content

Commit 764b45b

Browse files
mikeraclaude
andcommitted
Replace sleep-based timing with sync-based verification in tests
Replaced TimeUnit.MILLISECONDS.sleep() calls with NodeServer.sync() to ensure deterministic test verification. Tests now verify correct values are propagated rather than relying on broadcast counts or timing delays. Changes: - testAutomaticPropagation: Uses sync() and verifies value propagation - testMultipleUpdates: Renamed from testPropagatorBroadcastCount, now verifies each update is correctly received instead of counting broadcasts - Both tests use assertEquals to verify actual lattice values All 68 tests in convex-peer pass successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 00d3c9f commit 764b45b

File tree

1 file changed

+16
-34
lines changed

1 file changed

+16
-34
lines changed

convex-peer/src/test/java/convex/node/LatticePropagatorTest.java

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,10 @@ public void testPropagatorAutoStart() {
104104
* 1. The propagator detects value changes
105105
* 2. The propagator broadcasts to connected peers
106106
* 3. Broadcasts are sent automatically without manual intervention
107-
* 4. broadcast value is successfully obtained
107+
* 4. Broadcast value is successfully obtained by remote peer
108108
*/
109109
@Test
110110
public void testAutomaticPropagation() throws Exception {
111-
// Get initial broadcast count
112-
long initialBroadcastCount = server2.getPropagator().getBroadcastCount();
113-
114111
// Get the :data keyword
115112
Keyword dataKeyword = Keyword.intern("data");
116113

@@ -129,31 +126,22 @@ public void testAutomaticPropagation() throws Exception {
129126
Index<Hash, ACell> updatedDataIndex = dataIndex.assoc(valueHash, testValue);
130127
server2.updateLocalPath(updatedDataIndex, dataKeyword);
131128

132-
// Wait for propagator to detect change and broadcast (up to 1 second)
133-
server1.sync();
134-
135-
// Verify propagator detected the change and broadcasted
136-
long finalBroadcastCount = server2.getPropagator().getBroadcastCount();
137-
assertTrue(finalBroadcastCount > initialBroadcastCount,
138-
"Propagator should have detected value change and broadcasted to peers");
129+
// Sync server1 to ensure it has received the broadcast from server2
130+
assertTrue(server1.sync(), "Sync should complete successfully");
139131

140-
// Verify the broadcast count increased by at least 1
141-
assertTrue((finalBroadcastCount - initialBroadcastCount) >= 1,
142-
"At least one broadcast should have been sent after value change");
143-
144-
assertEquals(testValue,RT.getIn(server1.getLocalValue(),dataKeyword,valueHash));
132+
// Verify server1 received the value from server2
133+
assertEquals(testValue, RT.getIn(server1.getLocalValue(), dataKeyword, valueHash),
134+
"Server1 should have received the value broadcast from server2");
145135
}
146136

147137
/**
148-
* Tests that propagator broadcast count increases with local updates.
138+
* Tests that multiple updates are successfully propagated to remote peers.
149139
*/
150140
@Test
151-
public void testPropagatorBroadcastCount() throws Exception {
152-
// Get initial broadcast count
153-
long initialCount = server1.getPropagator().getBroadcastCount();
154-
155-
// Perform multiple local updates to trigger broadcasts
141+
public void testMultipleUpdates() throws Exception {
142+
// Perform multiple local updates on server1
156143
Keyword dataKeyword = Keyword.intern("data");
144+
157145
for (int i = 0; i < 3; i++) {
158146
ACell testValue = CVMLong.create(1000 + i);
159147
Hash valueHash = Hash.get(testValue);
@@ -168,18 +156,12 @@ public void testPropagatorBroadcastCount() throws Exception {
168156
Index<Hash, ACell> updatedDataIndex = dataIndex.assoc(valueHash, testValue);
169157
server1.updateLocalPath(updatedDataIndex, dataKeyword);
170158

171-
// Small delay between updates to allow broadcasts to complete
172-
TimeUnit.MILLISECONDS.sleep(100);
173-
}
174-
175-
// Wait a bit for final broadcast to complete
176-
TimeUnit.MILLISECONDS.sleep(200);
159+
// Sync server2 to ensure it received the update from server1
160+
assertTrue(server2.sync(), "Sync should complete successfully for update " + (i + 1));
177161

178-
// Verify count increased
179-
long finalCount = server1.getPropagator().getBroadcastCount();
180-
assertTrue(finalCount > initialCount,
181-
"Propagator broadcast count should increase with local updates");
182-
assertTrue((finalCount - initialCount) >= 3,
183-
"Should have at least 3 broadcasts from 3 local updates");
162+
// Verify server2 received this specific value
163+
assertEquals(testValue, RT.getIn(server2.getLocalValue(), dataKeyword, valueHash),
164+
"Server2 should have received update " + (i + 1) + " from server1");
165+
}
184166
}
185167
}

0 commit comments

Comments
 (0)