Skip to content
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

Useing Awaitility for asynchroneous testing. #3392

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

CalvinKirs
Copy link
Member

@CalvinKirs CalvinKirs commented Jul 7, 2022

Descriptions of the changes in this PR:

Using Thread.sleep in a test is just generally a bad idea. It creates brittle tests that can fail unpredictably depending on environment ("Passes on my machine!") or load. So I used Awaitility for asynchroneous testing.

Such as:

Motivation

Using Thread.sleep in a test is generally a bad idea. It creates brittle tests that can fail unpredictably depending on the environment ("Passes on my machine!") or load

Changes

Useing Awaitility for asynchronous testing.
Useing Awaitility test AutoRecoveryMainTest
Useing Awaitilitytest BookieZKExpireTest

@@ -76,7 +78,7 @@ conf, new TestBookieImpl(conf),

int secondsToWait = 5;
while (!server.isRunning()) {
Thread.sleep(1000);
await().atMost(1000, TimeUnit.MILLISECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this loop should become

await().atMost(5, SECONDS).until(() -> server.isRunning())

@@ -95,11 +97,11 @@ conf, new TestBookieImpl(conf),
assertNotNull("Send thread not found", sendthread);

sendthread.suspend();
Thread.sleep(2 * conf.getZkTimeout());
await().atMost(2L * conf.getZkTimeout(), TimeUnit.MILLISECONDS).await();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can leave the sleep here, we are not waiting for a particular condition

sendthread.resume();

// allow watcher thread to run
Thread.sleep(3000);
await().atMost(3, TimeUnit.SECONDS).await();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await().atMost(5, SECONDS).until(() -> server.isBookieRunning() && server.isRunning())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx,done

}
Thread.sleep(1000);
}
await().atMost(20, SECONDS).until(()->!main1.auditorElector.isRunning() && !main1.replicationWorker.isRunning()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to keep the same timeout (10 seconds)

Thread.sleep(1000);
}
}
await().atMost(20, SECONDS).until(() -> main1.auditorElector.getAuditor() != null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to keep the same timeout (10 seconds)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks,updated

main.auditorElector.isRunning());
assertTrue("Replication worker should be running",
main.replicationWorker.isRunning());
await().atMost(1, SECONDS).untilAsserted(() ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the atMost logic and use the default most await time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default await time is 10s

assertTrue("Replication worker should be running",
main.replicationWorker.isRunning());

await().atMost(1, SECONDS).untilAsserted(()->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

sendthread.resume();

// allow watcher thread to run
Thread.sleep(3000);
await().atMost(3, TimeUnit.SECONDS).await();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@hangc0276 hangc0276 added this to the 4.16.0 milestone Jul 25, 2022
@shoothzj
Copy link
Member

@CalvinKirs Hi, could you please rebase this PR. Also I think there is a typo in your PR title. using instead of Useing

@StevenLuMT
Copy link
Member

This branch has conflicts that must be resolved

@hangc0276
Copy link
Contributor

ping @CalvinKirs, do you have time to resolve the above comments?

@CalvinKirs
Copy link
Member Author

ping @CalvinKirs, do you have time to resolve the above comments?

Hi, I think I've resolved what the comments said, what else do I need to do? Except for dealing with conflicts.

@hangc0276 hangc0276 modified the milestones: 4.16.0, 4.17.0 Jul 29, 2022
Thread.sleep(1000);
}
}
await().until(() -> main1.auditorElector.getAuditor() != null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's different than before? looks like the getCurrentAuditor() is different than getAuditor()

sendthread.suspend();
Thread.sleep(2 * conf.getZkTimeout());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is part of the testing. It wants to resume the send thread after 2* zkTimeout to test the bookie should still working even if the zk session is timeout.

@StevenLuMT
Copy link
Member

fix old workflow,please see #3455 for detail

@eolivelli eolivelli removed this from the 4.17.0 milestone May 3, 2024
@shoothzj
Copy link
Member

shoothzj commented May 4, 2024

@CalvinKirs Hi, thanks for your contribution, I want to move forward this PR. Could you please help rebase the code? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants