Skip to content

Commit

Permalink
Fix parallel output using per request standard output.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Jun 20, 2024
1 parent 20d9efe commit 7a974e6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion integration/hurl/tests_ok/stdout.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -Eeuo pipefail
hurl --verbose tests_ok/stdout.hurl
hurl --verbose --output - tests_ok/stdout.hurl


1 change: 1 addition & 0 deletions integration/hurl/tests_ok/stdout_parallel.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HelloHello
4 changes: 4 additions & 0 deletions integration/hurl/tests_ok/stdout_parallel.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'

hurl --parallel tests_ok/stdout.hurl
4 changes: 4 additions & 0 deletions integration/hurl/tests_ok/stdout_parallel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -Eeuo pipefail

hurl --parallel tests_ok/stdout.hurl
7 changes: 5 additions & 2 deletions packages/hurl/src/parallel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::io;

use crate::parallel::job::{Job, JobResult};
use crate::parallel::worker::WorkerId;
use crate::util::term::Stderr;
use crate::util::term::{Stderr, Stdout};

/// Represents a message sent from the worker to the runner (running on the main thread).
pub enum WorkerMessage {
Expand Down Expand Up @@ -110,16 +110,19 @@ pub struct CompletedMsg {
pub worker_id: WorkerId,
/// Result execution of the originator job, can successful or failed.
pub result: JobResult,
/// Standard output of the worker for this job.
pub stdout: Stdout,
/// Standard error of the worker for this job.
pub stderr: Stderr,
}

impl CompletedMsg {
/// Creates a new completed message: the job has completed, successfully or not.
pub fn new(worker_id: WorkerId, result: JobResult, stderr: Stderr) -> Self {
pub fn new(worker_id: WorkerId, result: JobResult, stdout: Stdout, stderr: Stderr) -> Self {
CompletedMsg {
worker_id,
result,
stdout,
stderr,
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/hurl/src/parallel/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ impl ParallelRunner {
if !msg.stderr.buffer().is_empty() {
stderr.eprint(msg.stderr.buffer());
}
if !msg.stdout.buffer().is_empty() {
let ret = stdout.write_all(msg.stdout.buffer());
if ret.is_err() {
return Err(JobError::IO("Issue writing to stdout".to_string()));
}
}

// Then, we print job output on standard output (the first response truncates
// exiting file, subsequent response appends bytes).
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/parallel/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Worker {
));
}
let job_result = JobResult::new(job, content, result);
let msg = CompletedMsg::new(worker_id, job_result, logger.stderr);
let msg = CompletedMsg::new(worker_id, job_result, stdout, logger.stderr);
_ = tx.send(WorkerMessage::Completed(msg));
});

Expand Down

0 comments on commit 7a974e6

Please sign in to comment.