Skip to content

Commit 281eea4

Browse files
authored
test(sql): fix flaky BitmapIndexConcurrentTest (#6059)
1 parent 2f70873 commit 281eea4

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

core/src/test/java/io/questdb/test/cairo/BitmapIndexConcurrentTest.java renamed to core/src/test/java/io/questdb/test/cairo/BitmapIndexConcurrentFuzzTest.java

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import java.util.concurrent.atomic.AtomicInteger;
4848
import java.util.concurrent.atomic.AtomicReference;
4949

50-
public class BitmapIndexConcurrentTest extends AbstractCairoTest {
50+
public class BitmapIndexConcurrentFuzzTest extends AbstractCairoTest {
5151
private static final int MAX_ID = 100;
5252

5353
@Test
@@ -217,45 +217,47 @@ private void testConcurrentOperations(Rnd masterRnd) throws Exception {
217217
startBarrier.await(); // Wait for all threads to be ready
218218

219219
Rnd rnd = new Rnd(seed0, seed1); // Unique deterministic seeds per thread
220-
while (!stopFlag.get() && errorCount.get() == 0) {
221-
try {
222-
String randomSymbol = "SYM" + (rnd.nextInt(100) + 1);
223-
String querySql = String.format(
224-
"SELECT symbol, count(*) FROM trades WHERE symbol = '%s' GROUP BY symbol",
225-
randomSymbol
226-
);
227-
228-
try (RecordCursorFactory factory = select(querySql)) {
229-
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
230-
int rowCount = 0;
231-
CharSequence foundSymbol = null;
232-
233-
while (cursor.hasNext()) {
234-
rowCount++;
235-
if (rowCount > 1) {
220+
try (var threadLocalContext = TestUtils.createSqlExecutionCtx(engine)) {
221+
while (!stopFlag.get() && errorCount.get() == 0) {
222+
try {
223+
String randomSymbol = "SYM" + (rnd.nextInt(100) + 1);
224+
String querySql = String.format(
225+
"SELECT symbol, count(*) FROM trades WHERE symbol = '%s' GROUP BY symbol",
226+
randomSymbol
227+
);
228+
229+
try (RecordCursorFactory factory = select(querySql, threadLocalContext)) {
230+
try (RecordCursor cursor = factory.getCursor(threadLocalContext)) {
231+
int rowCount = 0;
232+
CharSequence foundSymbol = null;
233+
234+
while (cursor.hasNext()) {
235+
rowCount++;
236+
if (rowCount > 1) {
237+
errorCount.incrementAndGet();
238+
firstError.compareAndSet(null, new AssertionError("Reader " + threadId + ": Multiple rows for symbol " + randomSymbol));
239+
return;
240+
}
241+
foundSymbol = cursor.getRecord().getSymA(0);
242+
}
243+
244+
if (rowCount == 1 && !Chars.equals(foundSymbol, randomSymbol)) {
236245
errorCount.incrementAndGet();
237-
firstError.compareAndSet(null, new AssertionError("Reader " + threadId + ": Multiple rows for symbol " + randomSymbol));
246+
firstError.compareAndSet(null, new AssertionError("Reader " + threadId + ": Expected " + randomSymbol + " but got " + foundSymbol));
238247
return;
239248
}
240-
foundSymbol = cursor.getRecord().getSymA(0);
241-
}
242249

243-
if (rowCount == 1 && !Chars.equals(foundSymbol, randomSymbol)) {
244-
errorCount.incrementAndGet();
245-
firstError.compareAndSet(null, new AssertionError("Reader " + threadId + ": Expected " + randomSymbol + " but got " + foundSymbol));
246-
return;
250+
// It's OK if rowCount is 0 or 1 (symbol might not exist yet or might exist)
251+
totalQueries.incrementAndGet();
247252
}
248-
249-
// It's OK if rowCount is 0 or 1 (symbol might not exist yet or might exist)
250-
totalQueries.incrementAndGet();
251253
}
252-
}
253254

254-
Os.sleep(rnd.nextInt(5) + 1);
255-
} catch (Exception e) {
256-
errorCount.incrementAndGet();
257-
firstError.compareAndSet(null, e);
258-
e.printStackTrace();
255+
Os.sleep(rnd.nextInt(5) + 1);
256+
} catch (Exception e) {
257+
errorCount.incrementAndGet();
258+
firstError.compareAndSet(null, e);
259+
e.printStackTrace();
260+
}
259261
}
260262
}
261263
} catch (Exception e) {

0 commit comments

Comments
 (0)