Skip to content

Commit

Permalink
fix: HttpClientBasic reporting error for reestablished connections (#473
Browse files Browse the repository at this point in the history
)

* fix: HttpClientBasic reporting error for reestablished connections

* Update services/network/HttpClientBasic.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BarisTanyeri and github-actions[bot] committed Nov 20, 2023
1 parent e72d48f commit 0619299
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions services/network/HttpClientBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ namespace services
state = State::connected;
StartTimeout();
Established();
sharedAccess.SetAction([this]()
{
Expire();
});
createdClientObserver(sharedAccess.MakeShared(static_cast<services::HttpClientObserver&>(*this)));
}

Expand Down
29 changes: 29 additions & 0 deletions services/network/test/TestHttpClientBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,32 @@ TEST_F(HttpClientBasicTest, ContentError_calls_stop_only_once)
controller->GenerateContentError();
controller->GenerateContentError();
}

TEST_F(HttpClientBasicTest, done_called_when_connection_is_reestablished)
{
EXPECT_CALL(*controller, Established());
httpClientObserverFactory->ConnectionEstablished([this](infra::SharedPtr<services::HttpClientObserver> client)
{
httpClient.Attach(client);
});

infra::StreamWriterMock writer;
httpClient.Observer().SendStreamAvailable(infra::UnOwnedSharedPtr(writer));

EXPECT_CALL(*controller, Error(true));
httpClient.Detach();

EXPECT_CALL(*controller, Established());
httpClientObserverFactory->ConnectionEstablished([this](infra::SharedPtr<services::HttpClientObserver> client)
{
httpClient.Attach(client);
});

httpClient.Observer().SendStreamAvailable(infra::UnOwnedSharedPtr(writer));

EXPECT_CALL(*controller, Done());
EXPECT_CALL(httpClient, CloseConnection());
httpClient.Observer().BodyComplete();

ForwardTime(std::chrono::minutes(1));
}

0 comments on commit 0619299

Please sign in to comment.