Skip to content

Commit

Permalink
Allow some tests to run in parallel, need to figure out how to mock t…
Browse files Browse the repository at this point in the history
…he time better before we able to run everything in parallel
  • Loading branch information
ardhitama committed Nov 16, 2020
1 parent 73d6f7a commit 097fc77
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 791 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ lint-strict:

test:
mkdir -p ./etc/out
ENVIRONMENT=test go test -failfast -count 1 -timeout 30s -race -covermode=atomic -coverprofile=etc/out/profile.cov ./... && go tool cover -func=etc/out/profile.cov
ENVIRONMENT=test go test -failfast -count 1 -timeout 30s -covermode=atomic -coverprofile=etc/out/profile.cov ./... && go tool cover -func=etc/out/profile.cov

47 changes: 32 additions & 15 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (
"time"

"github.com/gomodule/redigo/redis"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)

type TestContext struct{}

func TestClientWorkerPoolHeartbeats(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "TestClientWorkerPoolHeartbeats"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

wp := NewWorkerPool(TestContext{}, 10, ns, pool)
Expand Down Expand Up @@ -65,7 +68,7 @@ func TestClientWorkerPoolHeartbeats(t *testing.T) {

func TestClientWorkerObservations(t *testing.T) {
pool := newTestPool()
ns := "TestClientWorkerObservations"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -134,7 +137,7 @@ func TestClientWorkerObservations(t *testing.T) {

func TestClientQueues(t *testing.T) {
pool := newTestPool()
ns := "TestClientQueues"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -188,7 +191,7 @@ func TestClientQueues(t *testing.T) {

func TestClientScheduledJobs(t *testing.T) {
pool := newTestPool()
ns := "TestClientScheduledJobs"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -239,7 +242,7 @@ func TestClientScheduledJobs(t *testing.T) {

func TestClientRetryJobs(t *testing.T) {
pool := newTestPool()
ns := "TestClientRetryJobs"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

setNowEpochSecondsMock(1425263409)
Expand Down Expand Up @@ -278,7 +281,7 @@ func TestClientRetryJobs(t *testing.T) {

func TestClientDeadJobs(t *testing.T) {
pool := newTestPool()
ns := "TestClientDeadJobs"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

setNowEpochSecondsMock(1425263409)
Expand Down Expand Up @@ -332,8 +335,10 @@ func TestClientDeadJobs(t *testing.T) {
}

func TestClientDeleteDeadJob(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "TestClientDeleteDeadJob"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

// Insert a dead job:
Expand Down Expand Up @@ -361,8 +366,10 @@ func TestClientDeleteDeadJob(t *testing.T) {
}

func TestClientRetryDeadJob(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "TestClientRetryDeadJob"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

// Insert a dead job:
Expand Down Expand Up @@ -417,8 +424,10 @@ func TestClientRetryDeadJob(t *testing.T) {
}

func TestClientRetryDeadJobWithArgs(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "testwork"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

// Enqueue a job with arguments
Expand Down Expand Up @@ -461,8 +470,10 @@ func TestClientRetryDeadJobWithArgs(t *testing.T) {
}

func TestClientDeleteAllDeadJobs(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "testwork"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

// Insert a dead job:
Expand All @@ -488,7 +499,7 @@ func TestClientDeleteAllDeadJobs(t *testing.T) {

func TestClientRetryAllDeadJobs(t *testing.T) {
pool := newTestPool()
ns := "testwork"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

setNowEpochSecondsMock(1425263409)
Expand Down Expand Up @@ -545,8 +556,10 @@ func TestClientRetryAllDeadJobs(t *testing.T) {
}

func TestClientRetryAllDeadJobsBig(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "testwork"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

conn := pool.Get()
Expand Down Expand Up @@ -614,8 +627,10 @@ func TestClientRetryAllDeadJobsBig(t *testing.T) {
}

func TestClientDeleteScheduledJob(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "testwork"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

// Delete an invalid job. Make sure we get error
Expand All @@ -635,8 +650,10 @@ func TestClientDeleteScheduledJob(t *testing.T) {
}

func TestClientDeleteScheduledUniqueJob(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "testwork"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

// Schedule a unique job. Delete it. Ensure we can schedule it again.
Expand All @@ -657,7 +674,7 @@ func TestClientDeleteScheduledUniqueJob(t *testing.T) {

func TestClientDeleteRetryJob(t *testing.T) {
pool := newTestPool()
ns := "testwork"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

setNowEpochSecondsMock(1425263409)
Expand Down
19 changes: 14 additions & 5 deletions dead_pool_reaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"time"

"github.com/gomodule/redigo/redis"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)

func TestDeadPoolReaper(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

conn := pool.Get()
Expand Down Expand Up @@ -92,8 +95,10 @@ func TestDeadPoolReaper(t *testing.T) {
}

func TestDeadPoolReaperNoHeartbeat(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "work"
ns := uuid.New().String()

conn := pool.Get()
defer conn.Close()
Expand Down Expand Up @@ -179,8 +184,10 @@ func TestDeadPoolReaperNoHeartbeat(t *testing.T) {
}

func TestDeadPoolReaperNoJobTypes(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

conn := pool.Get()
Expand Down Expand Up @@ -256,7 +263,7 @@ func TestDeadPoolReaperNoJobTypes(t *testing.T) {

func TestDeadPoolReaperWithWorkerPools(t *testing.T) {
pool := newTestPool()
ns := "work"
ns := uuid.New().String()
job1 := "job1"
stalePoolID := "aaa"
cleanKeyspace(ns, pool)
Expand Down Expand Up @@ -295,8 +302,10 @@ func TestDeadPoolReaperWithWorkerPools(t *testing.T) {
}

func TestDeadPoolReaperCleanStaleLocks(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)

conn := pool.Get()
Expand Down
17 changes: 12 additions & 5 deletions enqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)

func TestEnqueue(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
job, err := enqueuer.Enqueue("wat", Q{"a": 1, "b": "cool"})
Expand Down Expand Up @@ -53,8 +56,10 @@ func TestEnqueue(t *testing.T) {
}

func TestEnqueueIn(t *testing.T) {
t.Parallel()

pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)

Expand Down Expand Up @@ -101,7 +106,7 @@ func TestEnqueueIn(t *testing.T) {

func TestEnqueueUnique(t *testing.T) {
pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
var mutex = &sync.Mutex{}
Expand Down Expand Up @@ -177,7 +182,7 @@ func TestEnqueueUnique(t *testing.T) {

func TestEnqueueUniqueIn(t *testing.T) {
pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)

Expand Down Expand Up @@ -233,11 +238,13 @@ func TestEnqueueUniqueIn(t *testing.T) {
}

func TestEnqueueUniqueByKey(t *testing.T) {
t.Parallel()

var arg3 string
var arg4 string

pool := newTestPool()
ns := "work"
ns := uuid.New().String()
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
var mutex = &sync.Mutex{}
Expand Down
Loading

0 comments on commit 097fc77

Please sign in to comment.