diff --git a/dkron/agent_test.go b/dkron/agent_test.go index baf2e06c1..cd07fa407 100644 --- a/dkron/agent_test.go +++ b/dkron/agent_test.go @@ -254,7 +254,7 @@ func TestEncrypt(t *testing.T) { a.Stop() } -func Test_getRPCAddr(t *testing.T) { +func Test_advertiseRPCAddr(t *testing.T) { dir, err := ioutil.TempDir("", "dkron-test") require.NoError(t, err) defer os.RemoveAll(dir) @@ -277,7 +277,68 @@ func Test_getRPCAddr(t *testing.T) { time.Sleep(2 * time.Second) - getRPCAddr := a.getRPCAddr() + advertiseRPCAddr := a.advertiseRPCAddr() + exRPCAddr := a1Addr + ":6868" + + assert.Equal(t, exRPCAddr, advertiseRPCAddr) + + a.Stop() + + ip2, returnFn2 := testutil.TakeIP() + defer returnFn2() + a2Addr := ip2.String() + + c = DefaultConfig() + c.BindAddr = a2Addr + ":5000" + c.AdvertiseAddr = "8.8.8.8" + c.NodeName = "test1" + c.Server = true + c.Tags = map[string]string{"role": "test"} + c.LogLevel = logLevel + c.DevMode = true + c.DataDir = dir + + a = NewAgent(c) + a.Start() + + time.Sleep(2 * time.Second) + + advertiseRPCAddr = a.advertiseRPCAddr() + exRPCAddr = "8.8.8.8:6868" + + assert.Equal(t, exRPCAddr, advertiseRPCAddr) + + c.AdvertiseAddr = "8.8.8.8" + + assert.Equal(t, exRPCAddr, advertiseRPCAddr) + + a.Stop() +} + +func Test_bindRPCAddr(t *testing.T) { + dir, err := ioutil.TempDir("", "dkron-test") + require.NoError(t, err) + defer os.RemoveAll(dir) + + ip1, returnFn1 := testutil.TakeIP() + defer returnFn1() + a1Addr := ip1.String() + + c := DefaultConfig() + c.BindAddr = a1Addr + ":5000" + c.NodeName = "test1" + c.Server = true + c.Tags = map[string]string{"role": "test"} + c.LogLevel = logLevel + c.DevMode = true + c.DataDir = dir + + a := NewAgent(c) + a.Start() + + time.Sleep(2 * time.Second) + + getRPCAddr := a.bindRPCAddr() exRPCAddr := a1Addr + ":6868" assert.Equal(t, exRPCAddr, getRPCAddr) diff --git a/dkron/grpc_test.go b/dkron/grpc_test.go index 8561f03d8..36f582b0d 100644 --- a/dkron/grpc_test.go +++ b/dkron/grpc_test.go @@ -75,7 +75,7 @@ func TestGRPCExecutionDone(t *testing.T) { } rc := NewGRPCClient(nil, a) - rc.ExecutionDone(a.getRPCAddr(), testExecution) + rc.ExecutionDone(a.advertiseRPCAddr(), testExecution) execs, err := a.Store.GetExecutions("test") require.NoError(t, err) @@ -100,7 +100,7 @@ func TestGRPCExecutionDone(t *testing.T) { // Test store execution on a deleted job testExecution.FinishedAt = time.Now() - err = rc.ExecutionDone(a.getRPCAddr(), testExecution) + err = rc.ExecutionDone(a.advertiseRPCAddr(), testExecution) assert.Error(t, err, ErrExecutionDoneForDeletedJob) }