Revert "[opaque_test] Injection & Interposition on new thread"
This reverts commit 3eb3e2115be077b6361833473b48d516951d2a9a.
Reason for revert: Servicing the event streams on spawned threads cause all the channels created on that thread to misbehave once the thread is gone.
Bug: 73644
Multiply: fuchsia_component_v2_test: 30
Original change's description:
> [opaque_test] Injection & Interposition on new thread
>
> Sometimes test writers need to do thread sleeps or connect
> to services. These operations are blocking.
>
> If the main thread is blocked, injection and interposition
> will stop working. This may lead to a deadlock scenario.
>
> For example, consider the following scenario:
> * A test injects a service for component `foo`.
> * The test connects to an outgoing service of `foo`.
> This blocks the main thread until `foo`s outgoing directory is
> available. While the main thread is blocked, injection does not work.
> * Before serving the outgoing directory, `foo` connects to the
> injected service. This creates a deadlock scenario.
>
> To solve this problem, each injector + interposer is run on a new
> thread.
>
> Change-Id: I4d91252e664861388a3d116641931ea4a28fd576
> Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/435340
> Reviewed-by: Fady Samuel <fsamuel@google.com>
> Testability-Review: Fady Samuel <fsamuel@google.com>
> Commit-Queue: Xyan Bhatnagar <xbhatnag@google.com>
Change-Id: Ia4d47148e13c4bcb941cb935775d5b354018dfe3
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/513764
Reviewed-by: Bruno Dal Bo <brunodalbo@google.com>
Reviewed-by: Fady Samuel <fsamuel@google.com>
Reviewed-by: Xyan Bhatnagar <xbhatnag@google.com>
Fuchsia-Auto-Submit: Bruno Dal Bo <brunodalbo@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
diff --git a/src/sys/component_manager/tests/storage/integration_test.rs b/src/sys/component_manager/tests/storage/integration_test.rs
index fc3a88f7..ae22a82 100644
--- a/src/sys/component_manager/tests/storage/integration_test.rs
+++ b/src/sys/component_manager/tests/storage/integration_test.rs
@@ -8,10 +8,11 @@
component_events::{events::*, injectors::*, matcher::EventMatcher},
fidl_fidl_test_components as ftest, fidl_fuchsia_io as fio, fuchsia_async as fasync,
fuchsia_syslog as syslog, fuchsia_zircon as zx,
+ futures::lock::Mutex,
futures::StreamExt,
io_util::{self, OPEN_RIGHT_READABLE, OPEN_RIGHT_WRITABLE},
lazy_static::lazy_static,
- std::{path::PathBuf, sync::Arc, sync::Mutex},
+ std::{path::PathBuf, sync::Arc},
test_utils_lib::opaque_test::*,
};
@@ -85,7 +86,7 @@
// Create a mutex that is used to hold the response from the trigger
// service until after the tests inspects the storage.
let trigger_lock = Arc::new(Mutex::new(()));
- let trigger_guard = trigger_lock.lock();
+ let trigger_guard = trigger_lock.lock().await;
// The root component connects to the Trigger capability to create a
// rendezvous so the test can inspect storage before the child is
@@ -151,7 +152,7 @@
mut request_stream: ftest::TriggerRequestStream,
) -> Result<(), Error> {
while let Some(Ok(ftest::TriggerRequest::Run { responder })) = request_stream.next().await {
- let _guard = self.lock.lock();
+ let _guard = self.lock.lock().await;
responder.send("")?;
}
Ok(())
diff --git a/src/sys/lib/component-events/src/injectors.rs b/src/sys/lib/component-events/src/injectors.rs
index 7c99f9c..139a5ba3 100644
--- a/src/sys/lib/component-events/src/injectors.rs
+++ b/src/sys/lib/component-events/src/injectors.rs
@@ -42,11 +42,9 @@
.await
.expect("Could not subscribe to CapabilityRouted event for injection");
- // Spawn a new thread to listen to CapabilityRoutedEvents.
- // We use a new thread here because running this on the main thread may
- // not work if a test writer needs to do blocking operations.
+ // Spawn a new task to listen to CapabilityRoutedEvents
let injector = self.clone();
- fasync::Task::blocking(async move {
+ fasync::Task::spawn(async move {
let mut event_stream = EventStream::new(
server_end.into_stream().expect("Could not create EventStream from ServerEnd"),
);
diff --git a/src/sys/lib/component-events/src/interposers.rs b/src/sys/lib/component-events/src/interposers.rs
index e3855ec..882f011 100644
--- a/src/sys/lib/component-events/src/interposers.rs
+++ b/src/sys/lib/component-events/src/interposers.rs
@@ -45,10 +45,8 @@
.expect("Could not subscribe to CapabilityRouted event for interposition");
let (abort_handle, abort_registration) = AbortHandle::new_pair();
- // Spawn a new thread to listen to CapabilityRoutedEvents.
- // We use a new thread here because running this on the main thread may
- // not work if a test writer needs to do blocking operations.
- fasync::Task::blocking(
+ // Spawn a new task to listen to CapabilityRoutedEvents
+ fasync::Task::spawn(
Abortable::new(
async move {
let mut event_stream = EventStream::new(