Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions sdjournal/journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ func TestJournalGetEntry(t *testing.T) {
t.Fatalf("Error writing to journal: %s", err)
}

r := j.Wait(time.Duration(1) * time.Second)
if r < 0 {
t.Fatalf("Error waiting to journal")
}
time.Sleep(time.Duration(1) * time.Second)

Choose a reason for hiding this comment

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

Can you expand on why a hard sleep is better than waiting for the journal? This seems counter-intuitive to me as time.Sleep cries for flakes later on.

Copy link
Contributor Author

@lucab lucab Jul 5, 2016

Choose a reason for hiding this comment

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

From ML thread (quoting myself in lack of a better source):

sd_journal_wait() will trigger on *any* events, while sd_journal_get_data() 
will apply the filter and find no matching entries.

In our context, Wait() will return as soon as there is a new message available in the log even if it doesn't match the filter, in which case Next() will return EOF (if expected entry is not yet available).

This sleep could be replaced with something like a Wait&Next with a retrial counter, but it will not eliminate the flakiness of the test: it will then depend on the magic number of retrials and additionally also on how many events happen before our expected entry.

Choose a reason for hiding this comment

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

We could loop over sd_journal_wait()/sd_journal_get_data() until we eventually get our message matching the field, but I agree this could end up in an endless loop.

Not really happy about the time.Sleep at all, so let's observe this in subsequent CI builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me neither, but I think sdjournal would need to grow a C API for filtered event-triggering to properly address this usecase. May I go on and merge this as-is for now?


n, err := j.Next()
if err != nil {
Expand Down