Skip to content

Commit

Permalink
Enable integration tests with Daphne Helper
Browse files Browse the repository at this point in the history
Also, remove code for testing against Daphne running locally.
  • Loading branch information
cjpatton committed Apr 18, 2024
1 parent c43819c commit 1b884a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 44 deletions.
37 changes: 14 additions & 23 deletions integration_tests/src/daphne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use serde_json::json;
use testcontainers::{clients::Cli, GenericImage, RunnableImage};
use url::Url;

const DAPHNE_HELPER_IMAGE_NAME_AND_TAG: &str = "cloudflare/daphne-worker-helper:sha-f6b3ef1";
const DAPHNE_HELPER_IMAGE_NAME_AND_TAG: &str = "cloudflare/daphne-worker-helper:sha-4c612db";

/// Represents a running Daphne test instance.
pub struct Daphne<'a> {
daphne_container: Option<ContainerLogsDropGuard<'a, GenericImage>>,
daphne_container: ContainerLogsDropGuard<'a, GenericImage>,
}

impl<'a> Daphne<'a> {
Expand All @@ -28,7 +28,6 @@ impl<'a> Daphne<'a> {
network: &str,
task: &Task,
role: Role,
start_container: bool,
) -> Daphne<'a> {
let (endpoint, image_name_and_tag) = match role {
Role::Leader => panic!("A leader container image for Daphne is not yet available"),
Expand All @@ -43,22 +42,17 @@ impl<'a> Daphne<'a> {
.unwrap_or((image_name_and_tag, "latest"));

// Start the Daphne test container running.
let (port, daphne_container) = if start_container {
let runnable_image = RunnableImage::from(GenericImage::new(image_name, image_tag))
.with_network(network)
// Daphne uses the DAP_TRACING environment variable for its tracing subscriber.
.with_env_var(("DAP_TRACING", get_rust_log_level().1))
.with_container_name(endpoint.host_str().unwrap());
let daphne_container = ContainerLogsDropGuard::new(
test_name,
container_client.run(runnable_image),
ContainerLogsSource::Path("/logs".into()),
);
let port = daphne_container.get_host_port_ipv4(Self::INTERNAL_SERVING_PORT);
(port, Some(daphne_container))
} else {
(Self::INTERNAL_SERVING_PORT, None)
};
let runnable_image = RunnableImage::from(GenericImage::new(image_name, image_tag))
.with_network(network)
// Daphne uses the DAP_TRACING environment variable for its tracing subscriber.
.with_env_var(("DAP_TRACING", get_rust_log_level().1))
.with_container_name(endpoint.host_str().unwrap());
let daphne_container = ContainerLogsDropGuard::new(
test_name,
container_client.run(runnable_image),
ContainerLogsSource::Path("/logs".into()),
);
let port = daphne_container.get_host_port_ipv4(Self::INTERNAL_SERVING_PORT);

// Wait for Daphne container to begin listening on the port.
await_ready_ok(port).await;
Expand Down Expand Up @@ -129,9 +123,6 @@ impl<'a> Daphne<'a> {
/// Returns the port of the aggregator on the host.
pub fn port(&self) -> u16 {
self.daphne_container
.as_ref()
.map_or(Self::INTERNAL_SERVING_PORT, |container| {
container.get_host_port_ipv4(Self::INTERNAL_SERVING_PORT)
})
.get_host_port_ipv4(Self::INTERNAL_SERVING_PORT)
}
}
23 changes: 2 additions & 21 deletions integration_tests/tests/integration/daphne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ async fn daphne_janus() {
.build();

let container_client = container_client();
let leader = Daphne::new(
TEST_NAME,
&container_client,
&network,
&task,
Role::Leader,
true,
)
.await;
let leader = Daphne::new(TEST_NAME, &container_client, &network, &task, Role::Leader).await;
let helper =
JanusContainer::new(TEST_NAME, &container_client, &network, &task, Role::Helper).await;

Expand All @@ -72,7 +64,6 @@ async fn daphne_janus() {

// This test places Janus in the leader role & Daphne in the helper role.
#[tokio::test(flavor = "multi_thread")]
#[ignore = "Daphne does not currently support DAP-07 (issue #1669)"]
#[cfg(feature = "testcontainer")]
async fn janus_daphne() {
static TEST_NAME: &str = "janus_daphne";
Expand Down Expand Up @@ -102,15 +93,7 @@ async fn janus_daphne() {
let container_client = container_client();
let leader =
JanusContainer::new(TEST_NAME, &container_client, &network, &task, Role::Leader).await;
let helper = Daphne::new(
TEST_NAME,
&container_client,
&network,
&task,
Role::Helper,
true,
)
.await;
let helper = Daphne::new(TEST_NAME, &container_client, &network, &task, Role::Helper).await;

// Run the behavioral test.
submit_measurements_and_verify_aggregate(
Expand All @@ -125,7 +108,6 @@ async fn janus_daphne() {
/// This test places Janus in the leader role and Daphne in the helper role. Janus is run
/// in-process, while Daphne is run in Docker.
#[tokio::test(flavor = "multi_thread")]
#[ignore = "Daphne does not currently support DAP-07 (issue #1669)"]
async fn janus_in_process_daphne() {
static TEST_NAME: &str = "janus_in_process_daphne";
install_test_trace_subscriber();
Expand Down Expand Up @@ -153,7 +135,6 @@ async fn janus_in_process_daphne() {
&network,
&task_builder.clone().build(),
Role::Helper,
true,
)
.await;
task_builder = task_builder.with_helper_aggregator_endpoint(
Expand Down

0 comments on commit 1b884a8

Please sign in to comment.