-
Notifications
You must be signed in to change notification settings - Fork 468
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
adapter: Refactor environmentd test #23275
adapter: Refactor environmentd test #23275
Conversation
f53be46
to
b1d0a5f
Compare
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.
LGTM, couple of small nits/questions
b1d0a5f
to
4093922
Compare
use uuid::Uuid; | ||
|
||
#[mz_ore::test] | ||
#[mz_ore::test(tokio::test(flavor = "multi_thread", worker_threads = 1))] |
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.
What happens if you leave out flavor = "multi_thread", worker_threads = 1
?
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.
For some reason the test hangs, everything runs but we're blocked on cleanup. I haven't figured out exactly what's happening yet, but will dig in further when I have a free cycle or two
src/balancerd/tests/server.rs
Outdated
@@ -116,7 +115,7 @@ fn test_balancer() { | |||
|
|||
let (_role_tx, role_rx) = tokio::sync::mpsc::unbounded_channel(); | |||
const EXPIRES_IN_SECS: i64 = 50; | |||
let frontegg_server = start_mzcloud( | |||
let (frontegg_server, frontegg_future) = start_mzcloud( |
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.
This is going to conflict with #23176. Who's gonna merge first?!
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.
IMO #23176 unblocks more important workflows, so you can merge first!
src/balancerd/tests/server.rs
Outdated
@@ -127,6 +126,8 @@ fn test_balancer() { | |||
None, | |||
) | |||
.unwrap(); | |||
task::spawn(|| "test_balancer-frontegg_future", frontegg_future); |
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.
This is pretty ugly. After both these PRs merge we should do a similar refactor to the frontegg server so it's async-first also.
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.
Totally agree, once you merge #23176 I'll rebase and have a think about how to make this cleaner
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.
After rebasing on top of #23176 I moved the task::spawn
into the FronteggMockServer
itself, so we no longer need these spawn
calls!
fix docs in test_utils use mz_system constant
4093922
to
83f7e58
Compare
This PR only touches test code.
In this PR we refactor the
environmentd
(andbalancerd
) tests to be "async by default". There are a couple of key changes:test_utils.rs
are refactored to be async. They no longer take a runtime as an argument, or create a runtime themselves.Config
has been refactored toTestHarness
, which is a struct that handles test configuration and starting theenviromentd
server. There are two modes aTestHarness
can be created in, eitherasync fn start()
orfn start_blocking()
.async fn start()
returns aTestServer
, where all of the helper methods returntokio_postgres
types, and thus areasync
.fn start_blocking()
returns aTestServerWithRuntime
, where all of the helper methods returnpostgres
types, and thus are synchronous/blocking.The goal with the
TestHarness
change was to make migrating existing synchronous tests easy. The first part of that is the split between sync and async types, the other part is code refactoring. For example a sync test might look like:to refactor it to the async variant all you need to do is:
TestServer
, has a singlefn connect(...)
method which returns aConnectBuilder
. Instead of multiple different methods to configure how we want to connect to the runningenvironmentd
server, it's now bundled into this builder. The goal here was to reduce boilerplate and make it just as easy to use an async client as it is the sync client, e.g. handling notices with atokio_postgres
client isn't very straight forward.For example, if you just want to run some queries against the test server:
or if you want to configure the TLS used:
and much more:
Motivation
Making changes to our
environmentd
tests was painful because our tests and test utils were split between async and synchronous. For example, making changes to fix issues like https://github.com/MaterializeInc/database-issues/issues/6773 would end up being more complicated than necessary because some tests would rely on both async and sync test helpers.Tips for reviewer
Removing white space would be useful, and this PR is split into 3 commits which can be reviewed independently:
test_utils.rs
to make all helpers async, and introduce the split betweenTestServer
andTestServerWithRuntime
, as well as introduceConnectBuilder
.#[mz_ore::test(tokio::test)]
. Any tests that now relied on an async helper, or was already spawning futures on a runtime, were refactored.let server = TestHarness::default().start_blocking()
API. There are no functional changes in this commit, just code movement.Checklist
$T ⇔ Proto$T
mapping (possibly in a backwards-incompatible way), then it is tagged with aT-proto
label.