Skip to content

Commit

Permalink
Pass TcpListener to quickwit_serve in integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rdettai committed Aug 29, 2024
1 parent 7e6d4fc commit 0fd1322
Show file tree
Hide file tree
Showing 18 changed files with 514 additions and 357 deletions.
3 changes: 2 additions & 1 deletion quickwit/quickwit-cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use quickwit_common::runtimes::RuntimesConfig;
use quickwit_common::uri::{Protocol, Uri};
use quickwit_config::service::QuickwitService;
use quickwit_config::NodeConfig;
use quickwit_serve::{serve_quickwit, BuildInfo, EnvFilterReloadFn};
use quickwit_serve::{serve_quickwit, BuildInfo, EnvFilterReloadFn, TcpListenerResolver};
use quickwit_telemetry::payload::{QuickwitFeature, QuickwitTelemetryInfo, TelemetryEvent};
use tokio::signal;
use tracing::{debug, info};
Expand Down Expand Up @@ -114,6 +114,7 @@ impl RunCliCommand {
runtimes_config,
metastore_resolver,
storage_resolver,
TcpListenerResolver::default(),
shutdown_signal,
env_filter_reload_fn,
)
Expand Down
7 changes: 6 additions & 1 deletion quickwit/quickwit-config/src/node_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,12 @@ impl NodeConfig {

#[cfg(any(test, feature = "testsuite"))]
pub fn for_test() -> Self {
serialize::node_config_for_test()
serialize::node_config_for_tests()
}

#[cfg(any(test, feature = "testsuite"))]
pub fn for_test_from_ports(rest_listen_port: u16, grpc_listen_port: u16) -> Self {
serialize::node_config_for_tests_from_ports(rest_listen_port, grpc_listen_port)
}
}

Expand Down
18 changes: 13 additions & 5 deletions quickwit/quickwit-config/src/node_config/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ impl RestConfigBuilder {
}

#[cfg(any(test, feature = "testsuite"))]
pub fn node_config_for_test() -> NodeConfig {
use quickwit_common::net::find_available_tcp_port;

pub fn node_config_for_tests_from_ports(
rest_listen_port: u16,
grpc_listen_port: u16,
) -> NodeConfig {
let node_id = NodeId::new(default_node_id().unwrap());
let enabled_services = QuickwitService::supported_services();
let listen_address = Host::default();
let rest_listen_port = find_available_tcp_port().expect("OS should find an available port");
let rest_listen_addr = listen_address
.with_port(rest_listen_port)
.to_socket_addr()
Expand All @@ -426,7 +426,6 @@ pub fn node_config_for_test() -> NodeConfig {
.with_port(rest_listen_port)
.to_socket_addr()
.expect("default host should be an IP address");
let grpc_listen_port = find_available_tcp_port().expect("OS should find an available port");
let grpc_listen_addr = listen_address
.with_port(grpc_listen_port)
.to_socket_addr()
Expand Down Expand Up @@ -468,6 +467,15 @@ pub fn node_config_for_test() -> NodeConfig {
}
}

/// Creates a config with defaults that are suitable for testing.
///
/// Uses the default ports without ensuring that they are available.
#[cfg(any(test, feature = "testsuite"))]
pub fn node_config_for_tests() -> NodeConfig {
let default_rest = default_rest_listen_port();
node_config_for_tests_from_ports(default_rest, default_rest + 1)
}

#[cfg(test)]
mod tests {
use std::env;
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ quickwit-metastore = { workspace = true, features = ["testsuite"] }
quickwit-opentelemetry = { workspace = true, features = ["testsuite"] }
quickwit-proto = { workspace = true, features = ["testsuite"] }
quickwit-rest-client = { workspace = true }
quickwit-serve = { workspace = true }
quickwit-serve = { workspace = true, features = ["testsuite"] }
quickwit-storage = { workspace = true, features = ["testsuite"] }
Loading

0 comments on commit 0fd1322

Please sign in to comment.