mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-26 15:52:18 +08:00
Merge pull request #945 from Shopify/fix-test-default-port
Update tests to use the configured Redis address
This commit is contained in:
commit
ef0d32965f
@ -32,6 +32,7 @@ func (p *FakeConfigProvider) GetConfigs() ([]*PeriodicTaskConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewPeriodicTaskManager(t *testing.T) {
|
func TestNewPeriodicTaskManager(t *testing.T) {
|
||||||
|
redisConnOpt := getRedisConnOpt(t)
|
||||||
cfgs := []*PeriodicTaskConfig{
|
cfgs := []*PeriodicTaskConfig{
|
||||||
{Cronspec: "* * * * *", Task: NewTask("foo", nil)},
|
{Cronspec: "* * * * *", Task: NewTask("foo", nil)},
|
||||||
{Cronspec: "* * * * *", Task: NewTask("bar", nil)},
|
{Cronspec: "* * * * *", Task: NewTask("bar", nil)},
|
||||||
@ -43,14 +44,14 @@ func TestNewPeriodicTaskManager(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "with provider and redisConnOpt",
|
desc: "with provider and redisConnOpt",
|
||||||
opts: PeriodicTaskManagerOpts{
|
opts: PeriodicTaskManagerOpts{
|
||||||
RedisConnOpt: RedisClientOpt{Addr: ":6379"},
|
RedisConnOpt: redisConnOpt,
|
||||||
PeriodicTaskConfigProvider: &FakeConfigProvider{cfgs: cfgs},
|
PeriodicTaskConfigProvider: &FakeConfigProvider{cfgs: cfgs},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "with sync option",
|
desc: "with sync option",
|
||||||
opts: PeriodicTaskManagerOpts{
|
opts: PeriodicTaskManagerOpts{
|
||||||
RedisConnOpt: RedisClientOpt{Addr: ":6379"},
|
RedisConnOpt: redisConnOpt,
|
||||||
PeriodicTaskConfigProvider: &FakeConfigProvider{cfgs: cfgs},
|
PeriodicTaskConfigProvider: &FakeConfigProvider{cfgs: cfgs},
|
||||||
SyncInterval: 5 * time.Minute,
|
SyncInterval: 5 * time.Minute,
|
||||||
},
|
},
|
||||||
@ -58,7 +59,7 @@ func TestNewPeriodicTaskManager(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "with scheduler option",
|
desc: "with scheduler option",
|
||||||
opts: PeriodicTaskManagerOpts{
|
opts: PeriodicTaskManagerOpts{
|
||||||
RedisConnOpt: RedisClientOpt{Addr: ":6379"},
|
RedisConnOpt: redisConnOpt,
|
||||||
PeriodicTaskConfigProvider: &FakeConfigProvider{cfgs: cfgs},
|
PeriodicTaskConfigProvider: &FakeConfigProvider{cfgs: cfgs},
|
||||||
SyncInterval: 5 * time.Minute,
|
SyncInterval: 5 * time.Minute,
|
||||||
SchedulerOpts: &SchedulerOpts{
|
SchedulerOpts: &SchedulerOpts{
|
||||||
@ -74,13 +75,8 @@ func TestNewPeriodicTaskManager(t *testing.T) {
|
|||||||
t.Errorf("%s; NewPeriodicTaskManager returned error: %v", tc.desc, err)
|
t.Errorf("%s; NewPeriodicTaskManager returned error: %v", tc.desc, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewPeriodicTaskManagerError(t *testing.T) {
|
t.Run("error", func(t *testing.T) {
|
||||||
cfgs := []*PeriodicTaskConfig{
|
|
||||||
{Cronspec: "* * * * *", Task: NewTask("foo", nil)},
|
|
||||||
{Cronspec: "* * * * *", Task: NewTask("bar", nil)},
|
|
||||||
}
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
opts PeriodicTaskManagerOpts
|
opts PeriodicTaskManagerOpts
|
||||||
@ -88,7 +84,7 @@ func TestNewPeriodicTaskManagerError(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "without provider",
|
desc: "without provider",
|
||||||
opts: PeriodicTaskManagerOpts{
|
opts: PeriodicTaskManagerOpts{
|
||||||
RedisConnOpt: RedisClientOpt{Addr: ":6379"},
|
RedisConnOpt: redisConnOpt,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -105,6 +101,7 @@ func TestNewPeriodicTaskManagerError(t *testing.T) {
|
|||||||
t.Errorf("%s; NewPeriodicTaskManager did not return error", tc.desc)
|
t.Errorf("%s; NewPeriodicTaskManager did not return error", tc.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPeriodicTaskConfigHash(t *testing.T) {
|
func TestPeriodicTaskConfigHash(t *testing.T) {
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
package asynq
|
package asynq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/redis/go-redis/v9"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
|
||||||
"github.com/hibiken/asynq/internal/base"
|
"github.com/hibiken/asynq/internal/base"
|
||||||
"github.com/hibiken/asynq/internal/testutil"
|
"github.com/hibiken/asynq/internal/testutil"
|
||||||
@ -114,7 +114,7 @@ func TestSchedulerWhenRedisDown(t *testing.T) {
|
|||||||
|
|
||||||
// Connect to non-existent redis instance to simulate a redis server being down.
|
// Connect to non-existent redis instance to simulate a redis server being down.
|
||||||
scheduler := NewScheduler(
|
scheduler := NewScheduler(
|
||||||
RedisClientOpt{Addr: ":9876"},
|
RedisClientOpt{Addr: ":9876"}, // no Redis listening to this port.
|
||||||
&SchedulerOpts{EnqueueErrorHandler: errorHandler},
|
&SchedulerOpts{EnqueueErrorHandler: errorHandler},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func TestServerRun(t *testing.T) {
|
|||||||
ignoreOpt := goleak.IgnoreTopFunction("github.com/redis/go-redis/v9/internal/pool.(*ConnPool).reaper")
|
ignoreOpt := goleak.IgnoreTopFunction("github.com/redis/go-redis/v9/internal/pool.(*ConnPool).reaper")
|
||||||
defer goleak.VerifyNone(t, ignoreOpt)
|
defer goleak.VerifyNone(t, ignoreOpt)
|
||||||
|
|
||||||
srv := NewServer(RedisClientOpt{Addr: ":6379"}, Config{LogLevel: testLogLevel})
|
srv := NewServer(getRedisConnOpt(t), Config{LogLevel: testLogLevel})
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
// Make sure server exits when receiving TERM signal.
|
// Make sure server exits when receiving TERM signal.
|
||||||
@ -110,7 +110,7 @@ func TestServerRun(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServerErrServerClosed(t *testing.T) {
|
func TestServerErrServerClosed(t *testing.T) {
|
||||||
srv := NewServer(RedisClientOpt{Addr: ":6379"}, Config{LogLevel: testLogLevel})
|
srv := NewServer(getRedisConnOpt(t), Config{LogLevel: testLogLevel})
|
||||||
handler := NewServeMux()
|
handler := NewServeMux()
|
||||||
if err := srv.Start(handler); err != nil {
|
if err := srv.Start(handler); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -123,7 +123,7 @@ func TestServerErrServerClosed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServerErrNilHandler(t *testing.T) {
|
func TestServerErrNilHandler(t *testing.T) {
|
||||||
srv := NewServer(RedisClientOpt{Addr: ":6379"}, Config{LogLevel: testLogLevel})
|
srv := NewServer(getRedisConnOpt(t), Config{LogLevel: testLogLevel})
|
||||||
err := srv.Start(nil)
|
err := srv.Start(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Starting server with nil handler: (*Server).Start(nil) did not return error")
|
t.Error("Starting server with nil handler: (*Server).Start(nil) did not return error")
|
||||||
@ -132,7 +132,7 @@ func TestServerErrNilHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServerErrServerRunning(t *testing.T) {
|
func TestServerErrServerRunning(t *testing.T) {
|
||||||
srv := NewServer(RedisClientOpt{Addr: ":6379"}, Config{LogLevel: testLogLevel})
|
srv := NewServer(getRedisConnOpt(t), Config{LogLevel: testLogLevel})
|
||||||
handler := NewServeMux()
|
handler := NewServeMux()
|
||||||
if err := srv.Start(handler); err != nil {
|
if err := srv.Start(handler); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -153,7 +153,7 @@ func TestServerWithRedisDown(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
r := rdb.NewRDB(setup(t))
|
r := rdb.NewRDB(setup(t))
|
||||||
testBroker := testbroker.NewTestBroker(r)
|
testBroker := testbroker.NewTestBroker(r)
|
||||||
srv := NewServer(RedisClientOpt{Addr: ":6379"}, Config{LogLevel: testLogLevel})
|
srv := NewServer(getRedisConnOpt(t), Config{LogLevel: testLogLevel})
|
||||||
srv.broker = testBroker
|
srv.broker = testBroker
|
||||||
srv.forwarder.broker = testBroker
|
srv.forwarder.broker = testBroker
|
||||||
srv.heartbeater.broker = testBroker
|
srv.heartbeater.broker = testBroker
|
||||||
|
Loading…
Reference in New Issue
Block a user