Fix several race conditions

The fixes are specific to unit test environment.

PiperOrigin-RevId: 546342096
This commit is contained in:
Janusz Sobczak
2023-07-07 11:53:50 -07:00
committed by Copybara-Service
parent 61820e49fb
commit ca9bbd3a9c
6 changed files with 65 additions and 28 deletions
+17
View File
@@ -125,5 +125,22 @@ TEST(Borrowable, BorrowIsExclusive) {
EXPECT_NE(lender.GetBorrowable().Borrow()->GetValue(), kDefaultValue);
}
TEST(Borrowable, DefaultBorrowableFails) {
Borrowable<int> borrowable;
EXPECT_FALSE(borrowable.Borrow());
}
TEST(Borrowable, CopyBorrowable) {
constexpr int kValue = 1;
Lender<int> lender(kValue);
Borrowable<int> borrowable = lender.GetBorrowable();
Borrowable<int> copy = borrowable;
Borrowed<int> borrowed = copy.Borrow();
ASSERT_TRUE(borrowed);
EXPECT_EQ(*borrowed, kValue);
}
} // namespace
} // namespace nearby