-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 29, check for bad client version #40
Open
dreamer-dead
wants to merge
5
commits into
abyss7:master
Choose a base branch
from
dreamer-dead:issue-29
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c80c919
ISSUE-29: Add status code for bad client version.
dreamer-dead 3e434a6
ISSUE-29: Add optional field client_version in Remote.
dreamer-dead 6f8cc4d
ISSUE-29: Check for bad client version in Absorber.
dreamer-dead 3c37592
ISSUE-29: Add new AbsorberTest.BadClientVersion unit test.
dreamer-dead 09cb638
Rename client_version->emitter_version and add config field.
dreamer-dead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,16 @@ namespace { | |
|
||
// S1..4 types can be one of the following: |String|, |Immutable|, |Literal| | ||
template <typename S1, typename S2, typename S3, typename S4 = String> | ||
net::Connection::ScopedMessage CreateMessage(const S1& source, | ||
const S2& action, | ||
const S3& compiler_version, | ||
const S4& language = S4()) { | ||
net::Connection::ScopedMessage CreateMessage( | ||
const S1& source, | ||
const S2& action, | ||
const S3& compiler_version, | ||
const S4& language = S4(), | ||
ui32 client_version = Absorber::kMinGoodClientVersion) { | ||
net::Connection::ScopedMessage message(new net::Connection::Message); | ||
auto* extension = message->MutableExtension(proto::Remote::extension); | ||
extension->set_source(source); | ||
extension->set_client_version(client_version); | ||
auto* compiler = extension->mutable_flags()->mutable_compiler(); | ||
compiler->set_version(compiler_version); | ||
extension->mutable_flags()->set_action(action); | ||
|
@@ -374,5 +377,88 @@ TEST_F(AbsorberTest, BadMessageStatus) { | |
<< "Daemon must not store references to the connection"; | ||
} | ||
|
||
TEST_F(AbsorberTest, BadClientVersion) { | ||
const String expected_host = "fake_host"; | ||
const ui16 expected_port = 12345; | ||
const String compiler_version("compiler_version"); | ||
const String compiler_path("compiler_path"); | ||
|
||
conf.mutable_absorber()->mutable_local()->set_host(expected_host); | ||
conf.mutable_absorber()->mutable_local()->set_port(expected_port); | ||
auto* version = conf.add_versions(); | ||
version->set_version(compiler_version); | ||
version->set_path(compiler_path); | ||
|
||
listen_callback = | ||
[&expected_host, expected_port](const String& host, ui16 port, String*) { | ||
EXPECT_EQ(expected_host, host); | ||
EXPECT_EQ(expected_port, port); | ||
return true; | ||
}; | ||
connect_callback = [](net::TestConnection* connection) { | ||
connection->CallOnSend([](const net::Connection::Message& message) { | ||
EXPECT_TRUE(message.HasExtension(net::proto::Status::extension)); | ||
const auto& status = message.GetExtension(net::proto::Status::extension); | ||
EXPECT_EQ(net::proto::Status::BAD_CLIENT_VERSION, status.code()); | ||
|
||
EXPECT_FALSE(message.HasExtension(proto::Result::extension)); | ||
}); | ||
}; | ||
|
||
absorber.reset(new Absorber(conf)); | ||
ASSERT_TRUE(absorber->Initialize()); | ||
|
||
auto connection1 = test_service->TriggerListen(expected_host, expected_port); | ||
{ | ||
SharedPtr<net::TestConnection> test_connection = | ||
std::static_pointer_cast<net::TestConnection>(connection1); | ||
|
||
auto message(CreateMessage(""_l, ""_l, ""_l, ""_l, 1)); | ||
EXPECT_TRUE( | ||
test_connection->TriggerReadAsync(std::move(message), StatusOK())); | ||
|
||
UniqueLock lock(send_mutex); | ||
ASSERT_TRUE(send_condition.wait_for(lock, std::chrono::seconds(1), | ||
[this] { return send_count == 1; })); | ||
} | ||
|
||
auto connection2 = test_service->TriggerListen(expected_host, expected_port); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part doesn't correspond to the test's purpose - according to its name. It's better to leave only the first connection. |
||
{ | ||
SharedPtr<net::TestConnection> test_connection = | ||
std::static_pointer_cast<net::TestConnection>(connection2); | ||
|
||
test_connection->CallOnSend([](const net::Connection::Message& message) { | ||
EXPECT_TRUE(message.HasExtension(net::proto::Status::extension)); | ||
const auto& status = message.GetExtension(net::proto::Status::extension); | ||
EXPECT_EQ(net::proto::Status::OK, status.code()); | ||
|
||
EXPECT_TRUE(message.HasExtension(proto::Result::extension)); | ||
EXPECT_TRUE(message.GetExtension(proto::Result::extension).has_obj()); | ||
}); | ||
auto message(CreateMessage("source"_l, "action"_l, compiler_version)); | ||
auto* extension = message->MutableExtension(proto::Remote::extension); | ||
extension->clear_client_version(); | ||
EXPECT_TRUE( | ||
test_connection->TriggerReadAsync(std::move(message), StatusOK())); | ||
|
||
UniqueLock lock(send_mutex); | ||
ASSERT_TRUE(send_condition.wait_for(lock, std::chrono::seconds(1), | ||
[this] { return send_count == 2; })); | ||
} | ||
|
||
absorber.reset(); | ||
|
||
EXPECT_EQ(1u, run_count); | ||
EXPECT_EQ(1u, listen_count); | ||
EXPECT_EQ(2u, connect_count); | ||
EXPECT_EQ(2u, connections_created); | ||
EXPECT_EQ(2u, read_count); | ||
EXPECT_EQ(2u, send_count); | ||
EXPECT_EQ(1, connection1.use_count()) | ||
<< "Daemon must not store references to the connection"; | ||
EXPECT_EQ(1, connection2.use_count()) | ||
<< "Daemon must not store references to the connection"; | ||
} | ||
|
||
} // namespace daemon | ||
} // namespace dist_clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this function only I can say that this approach is not anticipated. The backward-compatible version should be the field in the Absorber config. Since the usual situation is when the clients (Emitters) are updated much more often than Absorbers, it's convenient to update this field without redistributing the new package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will do.