Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
added sync for testcases. currently execution is not guaranteed for P…
Browse files Browse the repository at this point in the history
…erformIn
  • Loading branch information
sio4 authored and paganotoni committed Apr 21, 2022
1 parent 9195c04 commit 11507d3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions worker/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package worker

import (
"context"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -160,15 +161,21 @@ func Test_Simple_PerformAt(t *testing.T) {
w := NewSimple()
r.NoError(w.Start(context.Background()))

wg := &sync.WaitGroup{}
wg.Add(1)

w.Register("x", func(Args) error {
hit = true
wg.Done()
return nil
})
w.PerformAt(Job{
Handler: "x",
}, time.Now().Add(5*time.Millisecond))

time.Sleep(10 * time.Millisecond)
// how long does the handler take for assignment? hmm,
time.Sleep(100 * time.Millisecond)
wg.Wait()
r.True(hit)

r.NoError(w.Stop())
Expand All @@ -181,15 +188,21 @@ func Test_Simple_PerformIn(t *testing.T) {
w := NewSimple()
r.NoError(w.Start(context.Background()))

wg := &sync.WaitGroup{}
wg.Add(1)

w.Register("x", func(Args) error {
hit = true
wg.Done()
return nil
})
w.PerformIn(Job{
Handler: "x",
}, 5*time.Millisecond)

time.Sleep(10 * time.Millisecond)
// how long does the handler take for assignment? hmm,
time.Sleep(100 * time.Millisecond)
wg.Wait()
r.True(hit)

r.NoError(w.Stop())
Expand Down

0 comments on commit 11507d3

Please sign in to comment.