Skip to content

Commit

Permalink
fix: Return error when n_workers non-positive
Browse files Browse the repository at this point in the history
Bug: N/A
Change-Id: I524156fc6aa0bfa892c1eaeee051b0f68be2350f
GitOrigin-RevId: 5bebd87aebd61b25e26c057c30c72a8d47aa4512
  • Loading branch information
Privacy Sandbox Team authored and copybara-github committed Oct 3, 2024
1 parent 9240fe9 commit cc49da3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/roma/byob/dispatcher/dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ absl::Status Dispatcher::Init(const int listen_fd) {

absl::StatusOr<std::string> Dispatcher::LoadBinary(
std::filesystem::path binary_path, const int n_workers) {
if (n_workers <= 0) {
return absl::InvalidArgumentError(
absl::StrCat("`n_workers=", n_workers, "` must be positive"));
}
std::string code_token = ToString(Uuid::GenerateUuid());
LoadRequest payload;
{
std::ifstream ifs(std::move(binary_path), std::ios::binary);
if (!ifs.is_open()) {
return absl::InvalidArgumentError(
return absl::UnavailableError(
absl::StrCat("Cannot open ", binary_path.native()));
}
payload.set_binary_content(std::string(std::istreambuf_iterator<char>(ifs),
Expand Down
22 changes: 22 additions & 0 deletions src/roma/byob/dispatcher/dispatcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ TEST(DispatcherTest, ShutdownDispatcherThenWorker) {
worker.join();
}

TEST(DispatcherTest, LoadErrorsWhenNWorkersNonPositive) {
const int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
ASSERT_NE(fd, -1);
BindAndListenOnPath(fd, "abcd.sock");
absl::Cleanup cleanup = [] { EXPECT_EQ(::unlink("abcd.sock"), 0); };
absl::Notification done;
std::thread worker([&done] {
const int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
ASSERT_NE(fd, -1);
ConnectToPath(fd, "abcd.sock");
done.WaitForNotification();
EXPECT_EQ(::close(fd), 0);
});
Dispatcher dispatcher;
ASSERT_TRUE(dispatcher.Init(fd).ok());
const absl::StatusOr<std::string> code_token =
dispatcher.LoadBinary("src/roma/byob/udf/new_udf", /*n_workers=*/0);
EXPECT_FALSE(code_token.ok());
done.Notify();
worker.join();
}

TEST(DispatcherTest, LoadErrorsWhenFileDoesntExist) {
const int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
ASSERT_NE(fd, -1);
Expand Down

0 comments on commit cc49da3

Please sign in to comment.