On Sat, Sep 17, 2016 at 07:20:09PM +0200, gregor herrmann wrote:

> CPAN RT has one issue; don't know if it's related:
> https://rt.cpan.org/Public/Bug/Display.html?id=110239

I think it's a different issue.

> From starting at t/daemon.t my guess is that we're seeing a race
> condition or some other timing issue here -- the daemon writes to a
> log file and the test reads the logfile, and in one case the log
> message doesn't seem to be there (yet?). At least that's my current
> guess.

Indeed, the daemon first opens the file for writing and only then writes
it (see the logger script at top of daemon.t), while the test waits for
existence (-e) and then proceeds to check the file contents.

I think the attached patch should fix it. I was able to reproduce
the issue sporadically without the patch, and couldn't get it to
happen after applying this.

> I'm tempted to mark this log-reading test as TODO since this seems a
> bit fragile.

No objections, but let's try the patch first?
>From 96209b5ba3df009a495da31bee8e2540c3365ec5 Mon Sep 17 00:00:00 2001
From: Niko Tyni <nt...@debian.org>
Date: Sat, 17 Sep 2016 21:16:16 +0300
Subject: [PATCH] Fix a race condition in the test suite waiting for daemon log

There's a window where the daemon has created a log file but not yet
written anything into it. Wait for the file to become nonempty before
reading it to make sure we're past that window.

Bug-Debian: https://bugs.debian.org/834960
 t/daemon.t | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/daemon.t b/t/daemon.t
index 30763df..548af21 100644
--- a/t/daemon.t
+++ b/t/daemon.t
@@ -200,7 +200,7 @@ sub do_test
 	like($counter1, qr/^\d+$/, "counter1 - $name");
-	expect { -e "$tmp/log" };
+	expect { -s "$tmp/log" };
 	like(read_file("$tmp/log"), qr/START LOG/, "logged output");
 	expect { my @l = read_file("$tmp/log"); @l > 1 };

Reply via email to