Skip to content

Commit

Permalink
Restore test for stop with unresponsive redis
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-suhas committed Mar 5, 2021
1 parent 31eeb2d commit 72ebe01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions worker_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestWorkersPoolRunSingleThreaded(t *testing.T) {
assert.EqualValues(t, 0, listSize(pool, redisKeyJobs(ns, job1)))
assert.EqualValues(t, 0, listSize(pool, redisKeyJobsInProgress(ns, wp.workerPoolID, job1)))
assert.EqualValues(t, 0, getInt64(pool, redisKeyJobsLock(ns, job1)))
assert.EqualValues(t, 0, hgetInt64(pool, redisKeyJobsLockInfo(ns, job1), wp.workerPoolID))
assert.False(t, hexists(pool, redisKeyJobsLockInfo(ns, job1), wp.workerPoolID))
}

func TestWorkerPoolPauseSingleThreadedJobs(t *testing.T) {
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestWorkerPoolPauseSingleThreadedJobs(t *testing.T) {
assert.EqualValues(t, 0, listSize(pool, redisKeyJobs(ns, job1)))
assert.EqualValues(t, 0, listSize(pool, redisKeyJobsInProgress(ns, wp.workerPoolID, job1)))
assert.EqualValues(t, 0, getInt64(pool, redisKeyJobsLock(ns, job1)))
assert.EqualValues(t, 0, hgetInt64(pool, redisKeyJobsLockInfo(ns, job1), wp.workerPoolID))
assert.False(t, hexists(pool, redisKeyJobsLockInfo(ns, job1), wp.workerPoolID))
}

// Test Helpers
Expand Down
22 changes: 22 additions & 0 deletions worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,17 @@ func TestWorkersPaused(t *testing.T) {

// Test that in the case of an unavailable Redis server,
// the worker loop exits in the case of a WorkerPool.Stop
func TestStopWithUnavailableRedis(t *testing.T) {
redisPool := &redis.Pool{
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", "notworking:6379", redis.DialConnectTimeout(1*time.Second))
},
}
wp := NewWorkerPool(TestContext{}, 10, "work", redisPool)
wp.Start()
wp.Stop()
}

func TestStop(t *testing.T) {
s, err := miniredis.Run()
assert.Nil(t, err)
Expand Down Expand Up @@ -554,6 +565,17 @@ func hgetInt64(pool *redis.Pool, redisKey, hashKey string) int64 {
return v
}

func hexists(pool *redis.Pool, redisKey, hashKey string) bool {
conn := pool.Get()
defer conn.Close()

ok, err := redis.Bool(conn.Do("HEXISTS", redisKey, hashKey))
if err != nil {
panic("could not HEXISTS: " + err.Error())
}
return ok
}

func jobOnZset(pool *redis.Pool, key string) (int64, *Job) {
conn := pool.Get()
defer conn.Close()
Expand Down

0 comments on commit 72ebe01

Please sign in to comment.