Skip to content

Commit bd988f9

Browse files
hanidamlajmeta-codesync[bot]
authored andcommitted
add setStopSendingCallback override to MockQuicSocketDriver
Summary: Add a `stopSendingCb` field to `StreamState` and wire up a `setStopSendingCallback` mock on the socket. When a stop_sending event is delivered, invoke the per-stream callback (and clear it) after the connection-level `onStopSending`. Reviewed By: afrind Differential Revision: D98362303 fbshipit-source-id: dd5cad60440259af035b8716589528e0875b1b17
1 parent fb07ea9 commit bd988f9

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

proxygen/lib/http/session/test/MockQuicSocketDriver.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class MockQuicSocketDriver : public folly::EventBase::LoopCallback {
9494
folly::Optional<quic::ApplicationErrorCode> error;
9595
QuicSocket::ReadCallback* readCB{nullptr};
9696
QuicSocket::PeekCallback* peekCB{nullptr};
97+
quic::StopSendingCallback* stopSendingCb{nullptr};
9798
using ByteEventList = std::list<std::pair<uint64_t, ByteEventCallback*>>;
9899
ByteEventList txCallbacks;
99100
ByteEventList deliveryCallbacks;
@@ -287,6 +288,23 @@ class MockQuicSocketDriver : public folly::EventBase::LoopCallback {
287288
return {};
288289
}));
289290

291+
using StopSendingCBResult = quic::Expected<void, LocalErrorCode>;
292+
EXPECT_CALL(*sock_, setStopSendingCallback(testing::_, testing::_))
293+
.WillRepeatedly(testing::Invoke([this](StreamId id,
294+
quic::StopSendingCallback* cb)
295+
-> StopSendingCBResult {
296+
auto it = streams_.find(id);
297+
if (it == streams_.end()) {
298+
return quic::make_unexpected(LocalErrorCode::STREAM_NOT_EXISTS);
299+
}
300+
ERROR_IF(
301+
it->second.writeState == CLOSED,
302+
fmt::format("setStopSendingCallback on CLOSED streamId={}", id),
303+
return quic::make_unexpected(LocalErrorCode::STREAM_NOT_EXISTS));
304+
it->second.stopSendingCb = cb;
305+
return {};
306+
}));
307+
290308
EXPECT_CALL(*sock_, pauseRead(testing::_))
291309
.WillRepeatedly(testing::Invoke([this](StreamId id) -> ReadCBResult {
292310
checkNotWriteOnlyStream(id);
@@ -1475,6 +1493,9 @@ class MockQuicSocketDriver : public folly::EventBase::LoopCallback {
14751493
event.error->asApplicationErrorCode();
14761494
if (err) {
14771495
sock_->connCb_->onStopSending(event.streamId, *err);
1496+
if (auto* cb = std::exchange(stream.stopSendingCb, nullptr)) {
1497+
cb->onStopSending(event.streamId, *err);
1498+
}
14781499
}
14791500
}
14801501
return;

0 commit comments

Comments
 (0)