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

chore: Fix flaky test cases in cron_test.exs #1270

Closed
wants to merge 1 commit into from

Conversation

halfdan
Copy link
Contributor

@halfdan halfdan commented Mar 12, 2025

This commit addresses two flaky test cases in cron_text.exs where inserted_refs! returns multiple jobs.

 1) test evaluating reboot after acquiring leadership (Oban.Plugins.CronTest)
     test/oban/plugins/cron_test.exs:123
     Assertion with == failed
     code:  assert [1] == inserted_refs()
     left:  [1]
     right: [1, 1]
     stacktrace:
       test/oban/plugins/cron_test.exs:140: (test)

  2) test cron jobs are scheduled using the configured timezone (Oban.Plugins.CronTest)
     test/oban/plugins/cron_test.exs:86
     Assertion with == failed
     code:  assert [1] == inserted_refs()
     left:  [1]
     right: [1, 1]
     stacktrace:
       test/oban/plugins/cron_test.exs:98: (test)
Details

dbg() output from `def inserted_refs/0`

[test/oban/plugins/cron_test.exs:181: Oban.Plugins.CronTest.inserted_refs/0]
Job #=> Oban.Job
|> Repo.all() #=> [
  %Oban.Job{
    __meta__: #Ecto.Schema.Metadata<:loaded, "oban_jobs">,
    id: 5526,
    state: "available",
    queue: "alpha",
    worker: "Oban.Integration.Worker",
    args: %{
      "action" => "OK",
      "bin_pid" => "g1h3DW5vbm9kZUBub2hvc3QAAAGyAAAAAAAAAAA=",
      "ref" => 1
    },
    meta: %{},
    tags: [],
    errors: [],
    attempt: 0,
    attempted_by: nil,
    max_attempts: 20,
    priority: 0,
    attempted_at: nil,
    cancelled_at: nil,
    completed_at: nil,
    discarded_at: nil,
    inserted_at: ~U[2025-03-12 09:56:40.774371Z],
    scheduled_at: ~U[2025-03-12 09:56:40.774371Z],
    conf: nil,
    conflict?: false,
    replace: nil,
    unique: nil,
    unsaved_error: nil
  },
  %Oban.Job{
    __meta__: #Ecto.Schema.Metadata<:loaded, "oban_jobs">,
    id: 5527,
    state: "available",
    queue: "alpha",
    worker: "Oban.Integration.Worker",
    args: %{
      "action" => "OK",
      "bin_pid" => "g1h3DW5vbm9kZUBub2hvc3QAAALmAAAAAAAAAAA=",
      "ref" => 1
    },
    meta: %{"cron" => true, "cron_expr" => "@reboot", "cron_tz" => "Etc/UTC"},
    tags: [],
    errors: [],
    attempt: 0,
    attempted_by: nil,
    max_attempts: 20,
    priority: 0,
    attempted_at: nil,
    cancelled_at: nil,
    completed_at: nil,
    discarded_at: nil,
    inserted_at: ~U[2025-03-12 09:56:40.691725Z],
    scheduled_at: ~U[2025-03-12 09:56:40.691725Z],
    conf: nil,
    conflict?: false,
    replace: nil,
    unique: nil,
    unsaved_error: nil
  }
]

.

  1) test evaluating reboot after acquiring leadership (Oban.Plugins.CronTest)
     test/oban/plugins/cron_test.exs:123
     Assertion with == failed
     code:  assert [1] == inserted_refs()
     left:  [1]
     right: [1, 1]
     stacktrace:
       test/oban/plugins/cron_test.exs:140: (test)

@sorentwo
Copy link
Member

Thanks for the fix! I went with a different approach in b0b5fa2 to isolate the tests and keep them async.

@sorentwo sorentwo closed this Mar 12, 2025
@halfdan
Copy link
Contributor Author

halfdan commented Mar 12, 2025

That makes sense! I was trying to understand why the Postgres Sandbox wasn't providing enough isolation here.

Your solution is definitely more elegant than turning the test module sync.

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.

None yet

2 participants