Skip to content

Commit

Permalink
nr_consul_cache fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
a-elsheikh committed Sep 11, 2023
1 parent cc085a3 commit 803d29d
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions nameresolution/consul/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestResolveID(t *testing.T) {
serviceEntries := []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8600,
Meta: map[string]string{
"DAPR_PORT": "50005",
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestResolveID(t *testing.T) {
assert.Equal(t, 1, mockReg.getCalled)
waitTillTrueOrTimeout(time.Second, func() bool { return mockReg.addOrUpdateCalled == 1 })
assert.Equal(t, 1, mockReg.addOrUpdateCalled)
assert.Equal(t, "123.234.345.456:50005", addr)
assert.Equal(t, "10.3.245.137:50005", addr)

mockReg.getResult = &registryEntry{
services: serviceEntries,
Expand All @@ -290,7 +290,7 @@ func TestResolveID(t *testing.T) {
mock.mockHealth.serviceResult = []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8601,
Meta: map[string]string{
"DAPR_PORT": "50005",
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestResolveID(t *testing.T) {
serviceResult: []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8600,
Meta: map[string]string{
"DAPR_PORT": "50005",
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestResolveID(t *testing.T) {
assert.Equal(t, 1, mockReg.getCalled)
waitTillTrueOrTimeout(time.Second, func() bool { return mockReg.addOrUpdateCalled == 1 })
assert.Equal(t, 1, mockReg.addOrUpdateCalled)
assert.Equal(t, "123.234.345.456:50005", addr)
assert.Equal(t, "10.3.245.137:50005", addr)

// Remove
waitTillTrueOrTimeout(time.Second, func() bool { return mockReg.removeCalled == 1 })
Expand All @@ -384,7 +384,7 @@ func TestResolveID(t *testing.T) {
serviceResult: []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8600,
Meta: map[string]string{
"DAPR_PORT": "50005",
Expand Down Expand Up @@ -426,7 +426,7 @@ func TestResolveID(t *testing.T) {
assert.Equal(t, 1, mockReg.getCalled)
waitTillTrueOrTimeout(time.Second, func() bool { return mockReg.addOrUpdateCalled == 1 })
assert.Equal(t, 1, mockReg.addOrUpdateCalled)
assert.Equal(t, "123.234.345.456:50005", addr)
assert.Equal(t, "10.3.245.137:50005", addr)

// Blocking call will error as WaitIndex = 1
blockingCall <- 2
Expand Down Expand Up @@ -464,7 +464,7 @@ func TestResolveID(t *testing.T) {
serviceResult: []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8600,
Meta: map[string]string{
"DAPR_PORT": "50005",
Expand Down Expand Up @@ -498,7 +498,7 @@ func TestResolveID(t *testing.T) {
assert.Equal(t, 1, mockReg.getCalled)
waitTillTrueOrTimeout(time.Second, func() bool { return mockReg.addOrUpdateCalled == 1 })
assert.Equal(t, 1, mockReg.addOrUpdateCalled)
assert.Equal(t, "123.234.345.456:50005", addr)
assert.Equal(t, "10.3.245.137:50005", addr)

// Error and release blocking call
mock.mockHealth.serviceErr = &err
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestResolveID(t *testing.T) {
serviceResult: []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.245.255",
Address: "10.3.245.137",
Port: 8600,
Meta: map[string]string{
"DAPR_PORT": "50005",
Expand All @@ -554,7 +554,7 @@ func TestResolveID(t *testing.T) {

addr, _ := resolver.ResolveID(req)

assert.Equal(t, "123.234.245.255:50005", addr)
assert.Equal(t, "10.3.245.137:50005", addr)
},
},
{
Expand All @@ -579,8 +579,7 @@ func TestResolveID(t *testing.T) {
},
},
}
resolver := newResolver(logger.NewLogger("test"), &mock)
resolver.config = testConfig
resolver := newResolver(logger.NewLogger("test"), testConfig, &mock, &registry{})

addr, _ := resolver.ResolveID(req)

Expand All @@ -599,7 +598,7 @@ func TestResolveID(t *testing.T) {
serviceResult: []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.245.255",
Address: "10.3.245.137",
Port: 8600,
Meta: map[string]string{
"DAPR_PORT": "50005",
Expand All @@ -625,7 +624,7 @@ func TestResolveID(t *testing.T) {
for i := 0; i < 100; i++ {
addr, _ := resolver.ResolveID(req)

if addr == "123.234.245.255:50005" {
if addr == "10.3.245.137:50005" {
total1++
} else if addr == "234.245.255.228:50005" {
total2++
Expand All @@ -652,7 +651,7 @@ func TestResolveID(t *testing.T) {
serviceResult: []*consul.ServiceEntry{
{
Node: &consul.Node{
Address: "123.234.245.255",
Address: "10.3.245.137",
},
Service: &consul.AgentService{
Address: "",
Expand All @@ -664,7 +663,7 @@ func TestResolveID(t *testing.T) {
},
{
Node: &consul.Node{
Address: "123.234.245.255",
Address: "10.3.245.137",
},
Service: &consul.AgentService{
Address: "",
Expand All @@ -681,7 +680,7 @@ func TestResolveID(t *testing.T) {

addr, _ := resolver.ResolveID(req)

assert.Equal(t, "123.234.245.255:50005", addr)
assert.Equal(t, "10.3.245.137:50005", addr)
},
},
{
Expand Down Expand Up @@ -767,7 +766,7 @@ func TestRegistry(t *testing.T) {
result := []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8600,
},
},
Expand Down Expand Up @@ -804,7 +803,7 @@ func TestRegistry(t *testing.T) {
services: []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8600,
},
},
Expand Down Expand Up @@ -836,7 +835,7 @@ func TestRegistry(t *testing.T) {
services: []*consul.ServiceEntry{
{
Service: &consul.AgentService{
Address: "123.234.345.456",
Address: "10.3.245.137",
Port: 8600,
},
},
Expand Down

0 comments on commit 803d29d

Please sign in to comment.