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

Race condition in test_simple_match #55

Open
jlebon opened this issue Oct 5, 2018 · 3 comments
Open

Race condition in test_simple_match #55

jlebon opened this issue Oct 5, 2018 · 3 comments
Labels

Comments

@jlebon
Copy link
Contributor

jlebon commented Oct 5, 2018

In test_simple_match(), we have:

    journal::send(&[&filter, &msg]);
    assert!(j.match_flush().unwrap().match_add(key, value).is_ok());
    let r = j.next_record().unwrap();
    assert!(r.is_some());

But the issue is that the next record might not immediately be available. There's a delay for the daemon to process it and then it finally making it available to open cursors. Adding:

     journal::send(&[&filter, &msg]);
     assert!(j.match_flush().unwrap().match_add(key, value).is_ok());
+    thread::sleep(time::Duration::from_millis(1000));
     let r = j.next_record().unwrap();

as a test fixes it for me, though a cleaner course of action would probably be to expose the notification API and make use of it in the tests?

@lucab
Copy link
Contributor

lucab commented Oct 15, 2018

expose the notification API

Do you have a reference to which API is that?
I just double-checked in go-systemd testsuite and indeed artificial 1s pauses got inserted in all roundtrips there.

@jlebon
Copy link
Contributor Author

jlebon commented Oct 15, 2018

Do you have a reference to which API is that?

See the functions at https://www.freedesktop.org/software/systemd/man/sd_journal_get_fd.html, though I've never made use of them myself.

@codyps codyps added the bug label Sep 7, 2020
@codyps
Copy link
Owner

codyps commented Sep 7, 2020

Ya, this should use the Journal::wait() method. These tests been modified a bit since this comment: they now iterate over journal entries rather than assuming it'll get the right one immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants