Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pipes instead of file for logging in tests #3074

Merged
merged 18 commits into from
Mar 8, 2021

Conversation

zeegomo
Copy link
Contributor

@zeegomo zeegomo commented Mar 1, 2021

Use a pipe for reading logs from child processes instead of reading from files, because that caused synchronization problems.

The main problem is that reading from stdout is blocking, the current solution is to spawn a new thread that blocks on new messages and then send them back on a channel. It's not ideal because we spawn a new thread for each new process, but it should not be too much of a problem.
I also tried with async processes and output (tokio::process) but I had issues with I/O drivers not receiving updates in some cases and I dropped it.
Another option could be to use some crate that exposes non future-based non blocking reads (mio only supports unix)

@zeegomo zeegomo force-pushed the logger-from-pipe branch from 120f300 to 64e94f3 Compare March 1, 2021 12:33
@zeegomo zeegomo requested a review from dkijania March 1, 2021 13:10
@eugene-babichenko
Copy link
Contributor

Does this replace #3051 as a proper fix to the problem?

@zeegomo
Copy link
Contributor Author

zeegomo commented Mar 1, 2021

Yes, this should solve that problem

@eugene-babichenko
Copy link
Contributor

Please close #3051 then.

@zeegomo
Copy link
Contributor Author

zeegomo commented Mar 2, 2021

This is ready for review, it is still a draft because it points to a patched jortestkit

@mzabaluev
Copy link
Contributor

input-output-hk/jortestkit#59 merged, please update and rebase.

log_location: PathBuf,
error_lines: String,
},
#[error("error in logs. Error lines: {error_lines}, full content:{logs}")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[error("error in logs. Error lines: {error_lines}, full content:{logs}")]
#[error("error in logs. Error lines: {error_lines}, full content: {logs}")]

Not really sure it's useful to put the full JSON content in a single error printout. Maybe the test fixture handling this error can re-parse the logs field and print the lines out nicely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could reuse log formatting from tracing_subscriber::fmt but I'm not sure if it can be used independently, need to check.

@zeegomo zeegomo force-pushed the logger-from-pipe branch from 210e52e to 993ec4e Compare March 3, 2021 13:00
@zeegomo zeegomo marked this pull request as ready for review March 4, 2021 08:30
@mzabaluev
Copy link
Contributor

The nightly failure should be fixed by #2888

zeegomo added 12 commits March 5, 2021 15:45
Reading from file has some challenges associated with it. Namely
on some Os reads can see torn writes and invalid utf-8 sequences.
In addition, it is also pretty inefficient to read from file every
time we want to access the logs.

This solution is not the best one, we probably want to use some
other library or method that allows us to read from stdout in a
non blocking way.
Trait objects impose unnecessary bound for Sync/Send, so let's
use generics instead.

Add a dummy implementer of SyncNode to make using those types easier
and almost identical as before.
Move selection of node inside the method to avoid having to clone
the nodes. It would be impossible to use a reference since the argument
must be a immutable reference but the method needs a mutable one, and
they would be both from the same struct.
Change 'controller' method to consume self and add logger,
since we do not read from file anymore. Client can then use
a reference to the logger, but is important that there is only
one logger that reads from the child stdout.
With the new architecture there is only one instace of logger per
process, and this instance is controlled by the process itself.
It also makes sense that the process is responsible for knowing
when it started properly.
@zeegomo zeegomo force-pushed the logger-from-pipe branch from 13efbc8 to 483f1ae Compare March 5, 2021 14:47
@zeegomo zeegomo merged commit e76d92d into input-output-hk:master Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants