Skip to content

Commit

Permalink
[BACKPORT 2024.1][#8096] YSQL: Fix flaky test TestPgDdlConcurrency#te…
Browse files Browse the repository at this point in the history
…stModifiedTableWrite

Summary:
The test is runs a DDL thread concurrently with 10 DML threads in ASAN/TSAN
builds and 50 DML threads in other builds. With 50 threads it still takes too
much resources, with 10 threads it is more flaky.

This diff makes two changes:
(1) Use 10 DML threads for all builds to reduce test resources.
(2) Changed the test to run until one of the expected errors appear to make it
more reliable.
Jira: DB-4809

Original commit: e9311b4 / D40929

Test Plan:
On AlmaLinux:
./yb_build.sh release --java-test 'org.yb.pgsql.TestPgDdlConcurrency#testModifiedTableWrite' -n 100 --tp 1
./yb_build.sh asan --java-test 'org.yb.pgsql.TestPgDdlConcurrency#testModifiedTableWrite' -n 100 --tp 1
./yb_build.sh tsan --java-test 'org.yb.pgsql.TestPgDdlConcurrency#testModifiedTableWrite' -n 100 --tp 1
./yb_build.sh debug --java-test 'org.yb.pgsql.TestPgDdlConcurrency#testModifiedTableWrite' -n 100 --tp 1
./yb_build.sh fastdebug --gcc11 --java-test 'org.yb.pgsql.TestPgDdlConcurrency#testModifiedTableWrite' -n 100 --tp 1

On MacOS:
./yb_build.sh release --java-test 'org.yb.pgsql.TestPgDdlConcurrency#testModifiedTableWrite' -n 100 --tp 1

Reviewers: hsunder

Reviewed By: hsunder

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D40989
  • Loading branch information
myang2021 committed Jan 3, 2025
1 parent 4b890e1 commit cd17840
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ protected int getInitialNumTServers() {
public void testModifiedTableWrite() throws Exception {
try (Statement stmt = connection.createStatement()) {
stmt.execute("CREATE TABLE t(k INT PRIMARY KEY, v1 INT DEFAULT 10, v2 INT DEFAULT 20)");
int count = 50;
final int count = 10;

final AtomicBoolean errorsDetected = new AtomicBoolean(false);
final AtomicBoolean stopped = new AtomicBoolean(false);
final CyclicBarrier barrier = new CyclicBarrier(count);
Expand All @@ -50,9 +51,10 @@ public void testModifiedTableWrite() throws Exception {
b.withTServer(count % miniCluster.getNumTServers());
connections[i] = b.connect();
}
final AtomicInteger expectedExceptionsCount = new AtomicInteger(0);
threads[0] = new Thread(() -> {
try (Statement lstmt = connections[0].createStatement()) {
while (!stopped.get() && !errorsDetected.get()) {
while (!stopped.get() && !errorsDetected.get() && expectedExceptionsCount.get() == 0) {
barrier.await();
lstmt.execute("ALTER TABLE t DROP COLUMN IF EXISTS v");
lstmt.execute("ALTER TABLE t ADD COLUMN v INT DEFAULT 100");
Expand All @@ -67,13 +69,12 @@ public void testModifiedTableWrite() throws Exception {
barrier.reset();
}
});
final AtomicInteger expectedExceptionsCount = new AtomicInteger(0);
for (int i = 1; i < count; ++i) {
final int idx = i;
threads[i] = new Thread(() -> {
try (Statement lstmt = connections[idx].createStatement()) {
for (int item_idx = 0;
!stopped.get() && !errorsDetected.get() && item_idx < 1000000;
!stopped.get() && !errorsDetected.get() && expectedExceptionsCount.get() == 0;
item_idx += 2) {
barrier.await();
try {
Expand Down Expand Up @@ -108,8 +109,7 @@ public void testModifiedTableWrite() throws Exception {
});
}
Arrays.stream(threads).forEach(t -> t.start());
final long startTimeMs = System.currentTimeMillis();
while (System.currentTimeMillis() - startTimeMs < 10000 && !errorsDetected.get()) {
while (!errorsDetected.get() && expectedExceptionsCount.get() == 0) {
Thread.sleep(1000);
}
stopped.set(true);
Expand Down

0 comments on commit cd17840

Please sign in to comment.