Commit b69ffecf authored by Vojtech Vitek (V-Teq)'s avatar Vojtech Vitek (V-Teq)

More robust tests for priority queue

parent 98714c8d
......@@ -17,39 +17,66 @@ func TestPriorityQueue(t *testing.T) {
t.Fatal(err)
}
// Enqueue two jobs.
_, err = jobs.Enqueue(`{"request":"data"}`, "test:low")
// Enqueue three jobs.
_, err = jobs.Enqueue("data1", "test:low")
if err != nil {
t.Fatal(err)
t.Error(err)
}
_, err = jobs.Enqueue(`{"request":"data"}`, "test:high")
_, err = jobs.Enqueue("data2", "test:urgent")
if err != nil {
t.Fatal(err)
t.Error(err)
}
// Dequeue first job. Must be from high priority queue.
job1, err := jobs.Dequeue("test:high", "test:low")
_, err = jobs.Enqueue("data3", "test:high")
if err != nil {
t.Fatal(err)
t.Error(err)
}
if job1.Queue != "test:high" {
t.Fatal("unexpected priority")
// Dequeue first job.
job, err := jobs.Dequeue("test:urgent", "test:high", "test:low")
if err != nil {
t.Error(err)
}
err = jobs.Ack(job1)
err = jobs.Ack(job)
if err != nil {
t.Fatal(err)
t.Error(err)
}
if e := "test:urgent"; job.Queue != e {
t.Fatalf("expected %s, got %s", e, job.Queue)
}
if e := "data2"; job.Data != e {
t.Fatalf("expected %s, got %s", e, job.Data)
}
// Dequeue second job. Must be from low priority queue.
job2, err := jobs.Dequeue("test:high", "test:low")
// Dequeue second job.
job, err = jobs.Dequeue("test:urgent", "test:high", "test:low")
if err != nil {
t.Fatal(err)
t.Error(err)
}
if job2.Queue != "test:low" {
t.Fatal("unexpected priority")
err = jobs.Ack(job)
if err != nil {
t.Error(err)
}
if e := "test:high"; job.Queue != e {
t.Fatalf("expected %s, got %s", e, job.Queue)
}
if e := "data3"; job.Data != e {
t.Fatalf("expected %s, got %s", e, job.Data)
}
err = jobs.Ack(job2)
// Dequeue third job.
job, err = jobs.Dequeue("test:urgent", "test:high", "test:low")
if err != nil {
t.Fatal(err)
t.Error(err)
}
err = jobs.Ack(job)
if err != nil {
t.Error(err)
}
if e := "test:low"; job.Queue != e {
t.Fatalf("expected %s, got %s", e, job.Queue)
}
if e := "data1"; job.Data != e {
t.Fatalf("expected %s, got %s", e, job.Data)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment