Skip to content

Commit

Permalink
Replace expect with context in buck2_test_runner
Browse files Browse the repository at this point in the history
Summary: Same as the previous diff

Reviewed By: IanChilds

Differential Revision: D68480782

fbshipit-source-id: 022e1dae20fc680b6c0eb48500dc8e405af4f338
  • Loading branch information
Will-MingLun-Li authored and facebook-github-bot committed Jan 22, 2025
1 parent 766e717 commit 30fd11d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
15 changes: 8 additions & 7 deletions app/buck2_test_runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use buck2_test_api::grpc::TestOrchestratorClient;
use clap::Parser;
use futures::channel::mpsc::UnboundedReceiver;
use futures::StreamExt;
use futures::TryStreamExt;
use host_sharing::HostSharingRequirements;
use parking_lot::Mutex;

Expand Down Expand Up @@ -79,39 +80,39 @@ impl Buck2TestRunner {
let execution_response = self
.execute_test_from_spec(spec)
.await
.expect("Test execution request failed");
.context("Test execution request failed")?;

let execution_result = match execution_response {
ExecuteResponse::Result(r) => r,
ExecuteResponse::Cancelled => return TestStatus::OMITTED,
ExecuteResponse::Cancelled => return Ok(TestStatus::OMITTED),
};

let test_result = get_test_result(name, target_handle, execution_result);
let test_status = test_result.status.clone();

self.report_test_result(test_result)
.await
.expect("Test result reporting failed");
.context("Test result reporting failed")?;

test_status
Ok(test_status)
})
// Use an arbitrarily large buffer -- execution throttling will be handled by the Buck2
// executor, so no need to hold back on requests here.
.buffer_unordered(10000)
// If any individual test failed, consider the entire run to have failed.
.fold(
.try_fold(
RunVerdict::Pass,
|mut run_verdict, test_status| async move {
if test_status != TestStatus::PASS {
run_verdict = RunVerdict::Fail;
}
run_verdict
anyhow::Ok(run_verdict)
},
)
.await;

self.orchestrator_client
.end_of_test_results(run_verdict.exit_code())
.end_of_test_results(run_verdict?.exit_code())
.await
}

Expand Down
9 changes: 5 additions & 4 deletions app/buck2_test_runner/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use std::net::SocketAddr;

use anyhow::Context;
use buck2_grpc::DuplexChannel;
use clap::Parser;
use tokio::net::TcpStream;
Expand Down Expand Up @@ -39,19 +40,19 @@ impl Buck2TestRunnerTcp {
let orchestrator_addr: SocketAddr = self
.orchestrator_addr
.parse()
.expect("Invalid orchestrator address");
.context("Invalid orchestrator address")?;
let executor_addr: SocketAddr = self
.executor_addr
.parse()
.expect("Invalid executor address");
.context("Invalid executor address")?;

let orchestrator_io = TcpStream::connect(&orchestrator_addr)
.await
.expect("Failed to create orchestrator_io");
.context("Failed to create orchestrator_io")?;

let executor_io = TcpStream::connect(&executor_addr)
.await
.expect("Failed to create executor_io");
.context("Failed to create executor_io")?;

let executor_io = {
let (read, write) = tokio::io::split(executor_io);
Expand Down
5 changes: 3 additions & 2 deletions app/buck2_test_runner/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::os::unix::io::FromRawFd;
use std::os::unix::io::RawFd;
use std::os::unix::net::UnixStream as StdUnixStream;

use anyhow::Context;
use buck2_grpc::DuplexChannel;
use clap::Parser;
use tokio::net::UnixStream;
Expand Down Expand Up @@ -40,11 +41,11 @@ impl Buck2TestRunnerUnix {
// descriptors at worse, which is basically the best we can do anyway.
let orchestrator_io =
UnixStream::from_std(unsafe { StdUnixStream::from_raw_fd(self.orchestrator_fd) })
.expect("Failed to create orchestrator_io");
.context("Failed to create orchestrator_io")?;

let executor_io =
UnixStream::from_std(unsafe { StdUnixStream::from_raw_fd(self.executor_fd) })
.expect("Failed to create executor_io");
.context("Failed to create executor_io")?;

let executor_io = {
let (read, write) = tokio::io::split(executor_io);
Expand Down

0 comments on commit 30fd11d

Please sign in to comment.