make tests more deterministic

Summary:
One of the tests for mononoke admin (which I introduced recently) appears to be flaky. Sometimes, output from stdout (the error that terminates the program) and stderr (logs emitted while the program runs) is flipped.

I suspect this is caused by buffering, so this patch flushes all output before writing the error (if there was one).

An alternative approach here might be to write the final error to stderr instead of stdosut (so everything goes to stderr). That feels cleaner, but it does change the interface a little bit, so I didn't take that approach just yet. That said, if nobody objects, I'm happy to pick that approach instead.

Reviewed By: farnz

Differential Revision: D15146392

fbshipit-source-id: 67481afd4802cb48d24d19052988be4a83433efd
This commit is contained in:
Thomas Orozco 2019-04-30 02:31:06 -07:00 committed by Facebook Github Bot
parent 8f514219a1
commit 477670a03c

View File

@ -1477,6 +1477,11 @@ fn main() -> Result<()> {
let debug = matches.is_present("debug");
tokio::run(future.map_err(move |err| {
// Flush so output is ordered as expected in tests. Ignore errors since there is nothing we
// can do about them.
let _ = std::io::stdout().flush();
let _ = std::io::stderr().flush();
println!("{:?}", err);
if debug {
println!("\n============ DEBUG ERROR ============");