Commit c6676dbf authored by James Robinson's avatar James Robinson Committed by Commit Bot

[fuchsia][base] Fix up binding in AgentImplTest

Some tests in the AgentImplTest suite were accidentally sending FIDL
messages over unbound channels. This was not caught by the test because
the tests did not spin the run loop to let the asynchronous callbacks
run or not run. This error is caught by new instrumentation being added
to the FIDL bindings.

This fixes up the bindings mismatch, spins the run loop to perform the
asynchronous portions of the test, and also adds some cleanup logic
that is also necessary now that the asynchronous portion of the test is
executing.

Test: cr_fuchsia_base_unittests
Bug: fuchsia:63593
Change-Id: I251124d9099695fc56096fd7baeb7a8fb67fdf7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530268
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Auto-Submit: James Robinson <jamesr@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826395}
parent 02ffdfa4
...@@ -176,7 +176,7 @@ TEST_F(AgentImplTest, DifferentComponentIdSameService) { ...@@ -176,7 +176,7 @@ TEST_F(AgentImplTest, DifferentComponentIdSameService) {
base::testfidl::TestInterfacePtr test_interface2; base::testfidl::TestInterfacePtr test_interface2;
component_services2->ConnectToService( component_services2->ConnectToService(
base::testfidl::TestInterface::Name_, base::testfidl::TestInterface::Name_,
test_interface1.NewRequest().TakeChannel()); test_interface2.NewRequest().TakeChannel());
// Both TestInterface pointers should remain valid until we are done. // Both TestInterface pointers should remain valid until we are done.
test_interface1.set_error_handler([](zx_status_t status) { test_interface1.set_error_handler([](zx_status_t status) {
...@@ -196,6 +196,7 @@ TEST_F(AgentImplTest, DifferentComponentIdSameService) { ...@@ -196,6 +196,7 @@ TEST_F(AgentImplTest, DifferentComponentIdSameService) {
EXPECT_EQ(result, 3); EXPECT_EQ(result, 3);
quit_loop.Run(); quit_loop.Run();
}); });
loop.RunUntilIdle();
} }
// Call Add() via the second TestInterface, and verify that first Add() call's // Call Add() via the second TestInterface, and verify that first Add() call's
...@@ -207,10 +208,20 @@ TEST_F(AgentImplTest, DifferentComponentIdSameService) { ...@@ -207,10 +208,20 @@ TEST_F(AgentImplTest, DifferentComponentIdSameService) {
EXPECT_EQ(result, 7); EXPECT_EQ(result, 7);
quit_loop.Run(); quit_loop.Run();
}); });
loop.RunUntilIdle();
} }
test_interface1.set_error_handler(nullptr); // Cleanly unbind the test interfaces now that we're done with them.
test_interface2.set_error_handler(nullptr); test_interface1 = nullptr;
test_interface2 = nullptr;
// Tear down connections to the agent and let the error handlers unwind.
{
base::RunLoop loop;
component_services1.Unbind();
component_services2.Unbind();
loop.RunUntilIdle();
}
} }
// Verify that multiple connection attempts with the same component Id connect // Verify that multiple connection attempts with the same component Id connect
...@@ -232,7 +243,7 @@ TEST_F(AgentImplTest, SameComponentIdSameService) { ...@@ -232,7 +243,7 @@ TEST_F(AgentImplTest, SameComponentIdSameService) {
base::testfidl::TestInterfacePtr test_interface2; base::testfidl::TestInterfacePtr test_interface2;
component_services2->ConnectToService( component_services2->ConnectToService(
base::testfidl::TestInterface::Name_, base::testfidl::TestInterface::Name_,
test_interface1.NewRequest().TakeChannel()); test_interface2.NewRequest().TakeChannel());
// Both TestInterface pointers should remain valid until we are done. // Both TestInterface pointers should remain valid until we are done.
test_interface1.set_error_handler([](zx_status_t status) { test_interface1.set_error_handler([](zx_status_t status) {
...@@ -252,6 +263,7 @@ TEST_F(AgentImplTest, SameComponentIdSameService) { ...@@ -252,6 +263,7 @@ TEST_F(AgentImplTest, SameComponentIdSameService) {
EXPECT_EQ(result, 3); EXPECT_EQ(result, 3);
quit_loop.Run(); quit_loop.Run();
}); });
loop.RunUntilIdle();
} }
// Call Add() via the other TestInterface, and verify that the result of the // Call Add() via the other TestInterface, and verify that the result of the
...@@ -263,10 +275,20 @@ TEST_F(AgentImplTest, SameComponentIdSameService) { ...@@ -263,10 +275,20 @@ TEST_F(AgentImplTest, SameComponentIdSameService) {
EXPECT_EQ(result, 10); EXPECT_EQ(result, 10);
quit_loop.Run(); quit_loop.Run();
}); });
loop.RunUntilIdle();
} }
test_interface1.set_error_handler(nullptr); // Cleanly unbind the test interfaces now that we're done with them.
test_interface2.set_error_handler(nullptr); test_interface1 = nullptr;
test_interface2 = nullptr;
// Tear down connections to the agent and let the error handlers unwind.
{
base::RunLoop loop;
component_services1.Unbind();
component_services2.Unbind();
loop.RunUntilIdle();
}
} }
// Verify that connections to a service registered to keep-alive the // Verify that connections to a service registered to keep-alive the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment