Skip to content

Commit

Permalink
bug(pg): Demonstrating (or trying to) bug with many crons.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed Nov 8, 2023
1 parent e6ece3c commit 5ac98d2
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions backends/postgres/postgres_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,89 @@ func TestCron(t *testing.T) {
}
}

func TestMultipleCrons(t *testing.T) {
done := make(chan bool, 1)
defer close(done)
const cronOne = "* * * * * *"
const cronTwo = "1 * * * * *"
const cronThree = "2 * * * * *"
connString, _ := prepareAndCleanupDB(t)

ctx := context.TODO()
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), postgres.WithConnectionString(connString))
if err != nil {
t.Fatal(err)
}
defer nq.Shutdown(ctx)

{ // Start the first cron handler
h := handler.NewPeriodic(func(ctx context.Context) (err error) {
done <- true
return
})

h.WithOptions(
handler.JobTimeout(500*time.Millisecond),
handler.Concurrency(1),
)

err = nq.StartCron(ctx, cronOne, h)
if err != nil {
t.Error(err)
}
}

{ // Start the second cron handler
h := handler.NewPeriodic(func(ctx context.Context) (err error) {
done <- true
return
})

h.WithOptions(
handler.JobTimeout(500*time.Millisecond),
handler.Concurrency(1),
)

err = nq.StartCron(ctx, cronTwo, h)
if err != nil {
t.Error(err)
}
}

{ // Start the third cron handler
h := handler.NewPeriodic(func(ctx context.Context) (err error) {
done <- true
return
})

h.WithOptions(
handler.JobTimeout(500*time.Millisecond),
handler.Concurrency(1),
)

// Will hang here
fmt.Println("before cron three is started")
err = nq.StartCron(ctx, cronThree, h)
if err != nil {
t.Error(err)
}
fmt.Println("if you can see me things are working!")
}

// allow time for listener to start
time.Sleep(5 * time.Millisecond)

select {
case <-time.After(3 * time.Second):
err = errPeriodicTimeout
case <-done:
}

if err != nil {
t.Error(err)
}
}

func TestMultipleCronNodes(t *testing.T) {
jobsProcessed := sync.Map{}
const cron = "* * * * * *"
Expand Down

0 comments on commit 5ac98d2

Please sign in to comment.