-
Notifications
You must be signed in to change notification settings - Fork 16
Fix TestTDClient.testBulkImport to mitigate the failure #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1247,12 +1247,38 @@ public void testBulkImport() | |||||||||||||||
| bs = client.getBulkImportSession(session); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Check the data | ||||||||||||||||
| TDTable imported = client.listTables(SAMPLE_DB).stream().filter(input -> { | ||||||||||||||||
| return input.getName().equals(bulkImportTable); | ||||||||||||||||
| }).findFirst().get(); | ||||||||||||||||
| // Wait for data propagation after commit completion | ||||||||||||||||
| logger.info("Bulk import committed, waiting for data propagation"); | ||||||||||||||||
| Thread.sleep(TimeUnit.SECONDS.toMillis(10)); | ||||||||||||||||
|
|
||||||||||||||||
| assertEquals(numRowsInPart * 2, imported.getRowCount()); | ||||||||||||||||
| // Check the data with retry logic | ||||||||||||||||
| final int expectedRowCount = numRowsInPart * 2; | ||||||||||||||||
| logger.info("Expected row count: {}, Valid parts: {}, numRowsInPart: {}", expectedRowCount, numValidParts, numRowsInPart); | ||||||||||||||||
|
|
||||||||||||||||
| TDTable imported = null; | ||||||||||||||||
| long rowCountCheckDeadline = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(2); | ||||||||||||||||
| BackOff rowCountBackoff = new ExponentialBackOff(); | ||||||||||||||||
|
|
||||||||||||||||
| while (System.currentTimeMillis() < rowCountCheckDeadline) { | ||||||||||||||||
| imported = client.listTables(SAMPLE_DB).stream().filter(input -> { | ||||||||||||||||
| return input.getName().equals(bulkImportTable); | ||||||||||||||||
| }).findFirst().get(); | ||||||||||||||||
|
|
||||||||||||||||
| logger.info("Current row count: {}, expected: {}", imported.getRowCount(), expectedRowCount); | ||||||||||||||||
|
|
||||||||||||||||
| if (imported.getRowCount() == expectedRowCount) { | ||||||||||||||||
| break; | ||||||||||||||||
| } | ||||||||||||||||
| else if (imported.getRowCount() > 0) { | ||||||||||||||||
| logger.warn("Row count mismatch: expected {}, got {}", expectedRowCount, imported.getRowCount()); | ||||||||||||||||
| break; | ||||||||||||||||
|
Comment on lines
+1273
to
+1274
|
||||||||||||||||
| logger.warn("Row count mismatch: expected {}, got {}", expectedRowCount, imported.getRowCount()); | |
| break; | |
| fail("Row count mismatch: expected " + expectedRowCount + ", got " + imported.getRowCount()); |
Copilot
AI
Aug 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread.sleep() can throw InterruptedException which is not being handled. This should be wrapped in a try-catch block or the method signature should declare the exception.
| Thread.sleep(rowCountBackoff.nextWaitTimeMillis()); | |
| try { | |
| Thread.sleep(rowCountBackoff.nextWaitTimeMillis()); | |
| } catch (InterruptedException e) { | |
| Thread.currentThread().interrupt(); | |
| fail("Thread was interrupted while waiting for row count", e); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Thread.sleep() in tests can make them flaky and slow. Consider using a polling mechanism with shorter intervals instead of a fixed 10-second sleep before starting the retry loop.