Skip to content

Commit

Permalink
[Flaky-test] Fix TableCacheTest (#11717)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie-Jiang authored Oct 2, 2023
1 parent 5bfb008 commit 196b42b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ public void dropRealtimeTable(String tableName)
getControllerRequestClient().deleteTable(TableNameBuilder.REALTIME.tableNameWithType(tableName));
}

public void waitForEVToAppear(String tableNameWithType) {
TestUtils.waitForCondition(aVoid -> _helixResourceManager.getTableExternalView(tableNameWithType) != null, 60_000L,
"Failed to create the external view for table: " + tableNameWithType);
}

public void waitForEVToDisappear(String tableNameWithType) {
TestUtils.waitForCondition(aVoid -> _helixResourceManager.getTableExternalView(tableNameWithType) == null, 60_000L,
"Failed to clean up the external view for table: " + tableNameWithType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void testTableCache(boolean isCaseInsensitive)
// Add a table config
TableConfig tableConfig =
new TableConfigBuilder(TableType.OFFLINE).setTableName(RAW_TABLE_NAME).setSchemaName(SCHEMA_NAME).build();
TEST_INSTANCE.waitForEVToDisappear(tableConfig.getTableName());
TEST_INSTANCE.getHelixResourceManager().addTable(tableConfig);
// Wait for at most 10 seconds for the callback to add the table config to the cache
TestUtils.waitForCondition(
Expand Down Expand Up @@ -181,6 +180,10 @@ public void testTableCache(boolean isCaseInsensitive)
assertEquals(tableCache.getSchema(SCHEMA_NAME), expectedSchema);
assertEquals(tableCache.getColumnNameMap(SCHEMA_NAME), expectedColumnMap);

// Wait for external view to appear before deleting the table to prevent external view being created after the
// waitForEVToDisappear() call
TEST_INSTANCE.waitForEVToAppear(OFFLINE_TABLE_NAME);

// Remove the table config
TEST_INSTANCE.getHelixResourceManager().deleteOfflineTable(RAW_TABLE_NAME);
// Wait for at most 10 seconds for the callback to remove the table config from the cache
Expand Down Expand Up @@ -210,6 +213,9 @@ public void testTableCache(boolean isCaseInsensitive)
assertNull(tableCache.getColumnNameMap(RAW_TABLE_NAME));
assertEquals(schemaChangeListener._schemaList.size(), 0);
assertEquals(tableConfigChangeListener._tableConfigList.size(), 0);

// Wait for external view to disappear to ensure a clean start for the next test
TEST_INSTANCE.waitForEVToDisappear(OFFLINE_TABLE_NAME);
}

@DataProvider(name = "testTableCacheDataProvider")
Expand Down

0 comments on commit 196b42b

Please sign in to comment.