refactor(test): use tokio::sync::mpsc::unbounded_channel (#13881)

This causes to block one less thread when running "deno test"
subcommand.
This commit is contained in:
Bartek Iwańczuk 2022-03-09 01:34:31 +01:00 committed by Yoshiya Hinosawa
parent cf7bbea705
commit 38e58668dd
No known key found for this signature in database
GPG Key ID: 0E8BFAA8A5B4E92B
2 changed files with 9 additions and 9 deletions

View File

@ -8,10 +8,10 @@ use deno_core::OpState;
use deno_runtime::permissions::create_child_permissions;
use deno_runtime::permissions::ChildPermissionsArg;
use deno_runtime::permissions::Permissions;
use std::sync::mpsc::Sender;
use tokio::sync::mpsc::UnboundedSender;
use uuid::Uuid;
pub fn init(sender: Sender<TestEvent>) -> Extension {
pub fn init(sender: UnboundedSender<TestEvent>) -> Extension {
Extension::builder()
.ops(vec![
(
@ -84,7 +84,7 @@ fn op_dispatch_test_event(
event: TestEvent,
_: (),
) -> Result<(), AnyError> {
let sender = state.borrow::<Sender<TestEvent>>().clone();
let sender = state.borrow::<UnboundedSender<TestEvent>>().clone();
sender.send(event).ok();
Ok(())

View File

@ -50,11 +50,11 @@ use std::collections::HashSet;
use std::io::Write;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::sync::mpsc::channel;
use std::sync::mpsc::Sender;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
use tokio::sync::mpsc::unbounded_channel;
use tokio::sync::mpsc::UnboundedSender;
/// The test mode is used to determine how a specifier is to be tested.
#[derive(Debug, Clone, PartialEq)]
@ -444,7 +444,7 @@ async fn test_specifier(
permissions: Permissions,
specifier: ModuleSpecifier,
mode: TestMode,
channel: Sender<TestEvent>,
channel: UnboundedSender<TestEvent>,
options: TestSpecifierOptions,
) -> Result<(), AnyError> {
let mut worker = create_main_worker(
@ -787,7 +787,7 @@ async fn test_specifiers(
specifiers_with_mode
};
let (sender, receiver) = channel::<TestEvent>();
let (sender, mut receiver) = unbounded_channel::<TestEvent>();
let concurrent_jobs = options.concurrent_jobs;
let fail_fast = options.fail_fast;
@ -816,12 +816,12 @@ async fn test_specifiers(
create_reporter(concurrent_jobs.get() > 1, log_level != Some(Level::Error));
let handler = {
tokio::task::spawn_blocking(move || {
tokio::task::spawn(async move {
let earlier = Instant::now();
let mut summary = TestSummary::new();
let mut used_only = false;
for event in receiver.iter() {
while let Some(event) = receiver.recv().await {
match event {
TestEvent::Plan(plan) => {
summary.total += plan.total;