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

Add single process integration tests #2123

Merged
merged 5 commits into from
Oct 13, 2023

Conversation

divergentdave
Copy link
Collaborator

This is part of #2081. This PR adds new integration tests that run both Janus aggregator instances in-process, relying on the existing ephemeral database support for Postgres. This also includes one test with an in-process Janus leader and a Daphne helper running in a container.

Note that the divviup-ts integration tests, or tests with Daphne as the leader, are not supported with in-process aggregators yet. That will require making connections from inside a container to TCP servers on the host, which may be doable using host.docker.internal on Windows/Mac and --add-host with host-gateway on Linux, FWIW.

@divergentdave divergentdave requested a review from a team as a code owner October 13, 2023 16:52
@divergentdave divergentdave force-pushed the david/single-process-integration-test branch from b08e793 to 32dd4ca Compare October 13, 2023 16:55
Comment on lines 121 to 125
config_file: PathBuf::new(),
database_password: None,
datastore_keys,
otlp_tracing_metadata: Vec::new(),
otlp_metrics_metadata: Vec::new(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could we provide Default on CommonBinaryOptions and do CommonBinaryOptions { datastore_keys, ..Default::default() }?

AggregatorEndpointFragments::VirtualNetwork { path, .. } => path,
AggregatorEndpointFragments::Localhost { path } => path,
};
Url::parse(&format!("http://127.0.0.1:{port}{path}")).unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we use http://localhost:{port}{path} here just in case someone only has an IPv6 localhost? Though I notice that this was hard-coded to 127.0.0.1 in the existing code this refactors, so maybe we deliberately forced this to use IPv4 to avoid port collisions across the protocols...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using localhost leads to problems when connecting to Docker container ports, because the same exposed container port may be published at different ephemeral ports on 127.0.0.1 and ::1. When you combine that with our HTTP client doing happy eyeballs on both addresses for localhost, that resulted in wires getting crossed between different concurrently running tests. Sticking with 127.0.0.1 here and Container::get_host_port_ipv4() elsewhere keeps things straight.

@@ -56,3 +85,191 @@ impl<'a> Janus<'a> {
.get_host_port_ipv4(Aggregator::INTERNAL_SERVING_PORT)
}
}

/// Represents a running Janus test instance in this process.
pub struct JanusInProcess {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's loads of other tests (such as in janus_aggregator::aggregator::http_handlers) where we set up an in-process instance of Janus by calling janus_aggregator::aggregator::http_handlers::aggregator_handler. I wonder if we should adapt those to use this entry point, or otherwise unify them? Though I don't think that needs to happen in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using the handler directly in those tests means they can run without binding to a port, skip both sides of the HTTP protocol, and manipulate requests and responses in memory. (using trillium-testing) I think it makes sense to keep things as they are, because they each have a different area of interest.

@divergentdave divergentdave force-pushed the david/single-process-integration-test branch from 32dd4ca to 2d194ef Compare October 13, 2023 19:52
@divergentdave divergentdave merged commit ce4cc45 into main Oct 13, 2023
@divergentdave divergentdave deleted the david/single-process-integration-test branch October 13, 2023 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants