[
https://issues.apache.org/jira/browse/BEAM-9187?focusedWorklogId=518236&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-518236
]
ASF GitHub Bot logged work on BEAM-9187:
----------------------------------------
Author: ASF GitHub Bot
Created on: 01/Dec/20 02:12
Start Date: 01/Dec/20 02:12
Worklog Time Spent: 10m
Work Description: apilloud commented on a change in pull request #13448:
URL: https://github.com/apache/beam/pull/13448#discussion_r533024977
##########
File path:
runners/java-fn-execution/src/test/java/org/apache/beam/runners/fnexecution/control/DefaultJobBundleFactoryTest.java
##########
@@ -459,27 +461,28 @@ public void loadBalancesBundles() throws Exception {
verify(envFactory, Mockito.times(2)).createEnvironment(eq(environment),
any());
long tms = System.currentTimeMillis();
- AtomicBoolean closed = new AtomicBoolean();
- // close to free up environment for another bundle
- TimerTask closeBundleTask =
- new TimerTask() {
- @Override
- public void run() {
- try {
- b2.close();
- closed.set(true);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- };
- new Timer().schedule(closeBundleTask, 100);
-
+ ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor();
+ ScheduledFuture<Optional<Exception>> closingFuture =
+ executor.schedule(
+ () -> {
+ try {
+ b2.close();
+ return Optional.empty();
+ } catch (Exception e) {
Review comment:
nit: You can drop this, `Future` will catch exceptions, wrap them in a
`ExecutionException` and throw them out of `get`.
##########
File path:
runners/java-fn-execution/src/test/java/org/apache/beam/runners/fnexecution/control/DefaultJobBundleFactoryTest.java
##########
@@ -459,27 +461,28 @@ public void loadBalancesBundles() throws Exception {
verify(envFactory, Mockito.times(2)).createEnvironment(eq(environment),
any());
long tms = System.currentTimeMillis();
- AtomicBoolean closed = new AtomicBoolean();
- // close to free up environment for another bundle
- TimerTask closeBundleTask =
- new TimerTask() {
- @Override
- public void run() {
- try {
- b2.close();
- closed.set(true);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- };
- new Timer().schedule(closeBundleTask, 100);
-
+ ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor();
+ ScheduledFuture<Optional<Exception>> closingFuture =
+ executor.schedule(
+ () -> {
+ try {
+ b2.close();
+ return Optional.empty();
+ } catch (Exception e) {
+ return Optional.of(e);
+ }
+ },
+ 100,
+ TimeUnit.MILLISECONDS);
+
+ // This call should block until closingFuture has finished closing b2
RemoteBundle b3 = sbf.getBundle(orf, srh,
BundleProgressHandler.ignored());
- // ensure we waited for close
+ // ensure the previous call waited for close
Assert.assertThat(System.currentTimeMillis() - tms,
greaterThanOrEqualTo(100L));
- Assert.assertThat(closed.get(), is(true));
+ // This assertion includes a small delay to give the forked thread a
chance to finish if it's
+ // been blocked
+ Assert.assertThat(closingFuture.get(1, TimeUnit.MILLISECONDS),
equalTo(Optional.empty()));
Review comment:
nit: Small delays lead to flakes, for example if the system is busy and
doesn't get back to the forked thread. Does having a small timeout add any
value here? Could you just block?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 518236)
Time Spent: 20m (was: 10m)
> org.apache.beam.runners.fnexecution.control.DefaultJobBundleFactoryTest.loadBalancesBundles
> is flaky
> ----------------------------------------------------------------------------------------------------
>
> Key: BEAM-9187
> URL: https://issues.apache.org/jira/browse/BEAM-9187
> Project: Beam
> Issue Type: Test
> Components: runner-core
> Reporter: Etienne Chauchot
> Assignee: Brian Hulette
> Priority: P1
> Labels: flake, flaky-test
> Time Spent: 20m
> Remaining Estimate: 0h
>
> [org.apache.beam.runners.fnexecution.control.DefaultJobBundleFactoryTest.loadBalancesBundles|https://builds.apache.org/job/beam_PreCommit_Java_Commit/9730/testReport/junit/org.apache.beam.runners.fnexecution.control/DefaultJobBundleFactoryTest/loadBalancesBundles/]
> UTest seem to be flaky:
> [https://builds.apache.org/job/beam_PreCommit_Java_Commit/9730/testReport/junit/org.apache.beam.runners.fnexecution.control/DefaultJobBundleFactoryTest/loadBalancesBundles/]
>
> I have runner-core as tag but in reality this test is in
> org.apache.beam.runners.fnexecution.control but there is no corresponding tag
--
This message was sent by Atlassian Jira
(v8.3.4#803005)