-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
use direct executor to deflake tests #33187
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
package org.apache.beam.runners.dataflow.worker.windmill.client.grpc.stubs; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Function; | ||
|
@@ -31,6 +32,7 @@ | |
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.LoadingCache; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.RemovalListener; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.RemovalListeners; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.MoreExecutors; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -50,14 +52,11 @@ public final class ChannelCache implements StatusDataProvider { | |
|
||
private ChannelCache( | ||
Function<WindmillServiceAddress, ManagedChannel> channelFactory, | ||
RemovalListener<WindmillServiceAddress, ManagedChannel> onChannelRemoved) { | ||
RemovalListener<WindmillServiceAddress, ManagedChannel> onChannelRemoved, | ||
Executor channelCloser) { | ||
this.channelCache = | ||
CacheBuilder.newBuilder() | ||
.removalListener( | ||
RemovalListeners.asynchronous( | ||
onChannelRemoved, | ||
Executors.newCachedThreadPool( | ||
new ThreadFactoryBuilder().setNameFormat("GrpcChannelCloser").build()))) | ||
.removalListener(RemovalListeners.asynchronous(onChannelRemoved, channelCloser)) | ||
.build( | ||
new CacheLoader<WindmillServiceAddress, ManagedChannel>() { | ||
@Override | ||
|
@@ -72,11 +71,13 @@ public static ChannelCache create( | |
return new ChannelCache( | ||
channelFactory, | ||
// Shutdown the channels as they get removed from the cache, so they do not leak. | ||
notification -> shutdownChannel(notification.getValue())); | ||
notification -> shutdownChannel(notification.getValue()), | ||
Executors.newCachedThreadPool( | ||
new ThreadFactoryBuilder().setNameFormat("GrpcChannelCloser").build())); | ||
} | ||
|
||
@VisibleForTesting | ||
static ChannelCache forTesting( | ||
public static ChannelCache forTesting( | ||
Function<WindmillServiceAddress, ManagedChannel> channelFactory, Runnable onChannelShutdown) { | ||
return new ChannelCache( | ||
channelFactory, | ||
|
@@ -85,7 +86,9 @@ static ChannelCache forTesting( | |
notification -> { | ||
shutdownChannel(notification.getValue()); | ||
onChannelShutdown.run(); | ||
}); | ||
}, | ||
// Run the removal on the calling thread for better determinism in tests. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added, this doesn't change any behavior we just want the removal to run synchronously so we don't have to rely on waiting in tests |
||
MoreExecutors.directExecutor()); | ||
} | ||
|
||
private static void shutdownChannel(ManagedChannel channel) { | ||
|
@@ -108,6 +111,7 @@ public void remove(WindmillServiceAddress windmillServiceAddress) { | |
|
||
public void clear() { | ||
channelCache.invalidateAll(); | ||
channelCache.cleanUp(); | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"to make testing more deterministic" gives an impression that the change just fix tests, however the test code path then diverts from the real one.
Please provide more information in this comment why the race observed in the test does not affect production, for future reference.
If this indeed could happen in production then we should fix the code.
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.
In prod, this is to hand off the task from a thread that (may) perform network IO and we do not want the task to block that since it acquires a lock to do its work. Not needed in testing and can logically be called in line
Added comment.