mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
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:
parent
22dbbf75f3
commit
85cb6f2563
2 changed files with 9 additions and 9 deletions
|
@ -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(())
|
||||
|
|
|
@ -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)]
|
||||
|
@ -445,7 +445,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(
|
||||
|
@ -793,7 +793,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;
|
||||
|
||||
|
@ -822,12 +822,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;
|
||||
|
|
Loading…
Reference in a new issue