aboutsummaryrefslogtreecommitdiff
path: root/pw_transfer/client_test.cc
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-23 00:09:38 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-23 00:09:38 +0000
commitaff67b6bbc28eba4d1f4a4a12e116e63ab4813ea (patch)
treeb7892405559e1714c330ffb8ac9de9104296f4e3 /pw_transfer/client_test.cc
parent13960e09d00c4e8612da0a9084e0e051603f072b (diff)
parentf054515492af5132f685cb23fe11891ee77104c9 (diff)
downloadpigweed-aff67b6bbc28eba4d1f4a4a12e116e63ab4813ea.tar.gz
Change-Id: I018123259cd231d0e74933e492391999e36650e8
Diffstat (limited to 'pw_transfer/client_test.cc')
-rw-r--r--pw_transfer/client_test.cc29
1 files changed, 16 insertions, 13 deletions
diff --git a/pw_transfer/client_test.cc b/pw_transfer/client_test.cc
index 0340ac0c0..323570dcf 100644
--- a/pw_transfer/client_test.cc
+++ b/pw_transfer/client_test.cc
@@ -21,7 +21,6 @@
#include "pw_bytes/array.h"
#include "pw_rpc/raw/client_testing.h"
#include "pw_rpc/test_helpers.h"
-#include "pw_thread/sleep.h"
#include "pw_thread/thread.h"
#include "pw_thread_stl/options.h"
#include "pw_transfer_private/chunk_testing.h"
@@ -611,8 +610,8 @@ TEST_F(ReadTransfer, ResendsParametersIfSentRepeatedChunkDuringRecovery) {
EXPECT_EQ(transfer_status, OkStatus());
}
-constexpr chrono::SystemClock::duration kTestTimeout =
- std::chrono::milliseconds(50);
+// Use a long timeout to avoid accidentally triggering timeouts.
+constexpr chrono::SystemClock::duration kTestTimeout = std::chrono::seconds(30);
constexpr uint8_t kTestRetries = 3;
TEST_F(ReadTransfer, Timeout_ResendsCurrentParameters) {
@@ -780,7 +779,7 @@ TEST_F(ReadTransfer, Timeout_EndsTransferAfterMaxRetries) {
EXPECT_EQ(transfer_status, Status::Unknown());
}
- // Sleep one more time after the final retry. The client should cancel the
+ // Time out one more time after the final retry. The client should cancel the
// transfer at this point. As no packets were received from the server, no
// final status chunk should be sent.
transfer_thread_.SimulateClientTimeout(14);
@@ -788,9 +787,10 @@ TEST_F(ReadTransfer, Timeout_EndsTransferAfterMaxRetries) {
EXPECT_EQ(transfer_status, Status::DeadlineExceeded());
- // After finishing the transfer, nothing else should be sent. Verify this by
- // waiting for a bit.
- this_thread::sleep_for(kTestTimeout * 4);
+ // After finishing the transfer, nothing else should be sent.
+ transfer_thread_.SimulateClientTimeout(14);
+ transfer_thread_.SimulateClientTimeout(14);
+ transfer_thread_.SimulateClientTimeout(14);
ASSERT_EQ(payloads.size(), 4u);
}
@@ -1466,7 +1466,7 @@ TEST_F(WriteTransfer, Timeout_EndsTransferAfterMaxRetries) {
EXPECT_EQ(transfer_status, Status::Unknown());
}
- // Sleep one more time after the final retry. The client should cancel the
+ // Time out one more time after the final retry. The client should cancel the
// transfer at this point. As no packets were received from the server, no
// final status chunk should be sent.
transfer_thread_.SimulateClientTimeout(13);
@@ -1474,9 +1474,10 @@ TEST_F(WriteTransfer, Timeout_EndsTransferAfterMaxRetries) {
EXPECT_EQ(transfer_status, Status::DeadlineExceeded());
- // After finishing the transfer, nothing else should be sent. Verify this by
- // waiting for a bit.
- this_thread::sleep_for(kTestTimeout * 4);
+ // After finishing the transfer, nothing else should be sent.
+ transfer_thread_.SimulateClientTimeout(13);
+ transfer_thread_.SimulateClientTimeout(13);
+ transfer_thread_.SimulateClientTimeout(13);
ASSERT_EQ(payloads.size(), 4u);
// Ensure we don't leave a dangling reference to transfer_status.
@@ -1580,12 +1581,14 @@ TEST_F(WriteTransfer, ManualCancel) {
EXPECT_EQ(chunk.type(), Chunk::Type::kStart);
// Get a response from the server, then cancel the transfer.
+ // This must request a smaller chunk than the entire available write data to
+ // prevent the client from trying to send an additional finish chunk.
context_.server().SendServerStream<Transfer::Write>(EncodeChunk(
Chunk(ProtocolVersion::kLegacy, Chunk::Type::kParametersRetransmit)
.set_session_id(15)
.set_offset(0)
- .set_window_end_offset(64)
- .set_max_chunk_size_bytes(32)));
+ .set_window_end_offset(16)
+ .set_max_chunk_size_bytes(16)));
transfer_thread_.WaitUntilEventIsProcessed();
ASSERT_EQ(payloads.size(), 2u);