mirror of https://github.com/status-im/consul.git
remove a source of test panics (#13227)
This commit is contained in:
parent
a85b8a4705
commit
31526139fd
|
@ -1703,6 +1703,7 @@ func TestAgent_Reload(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
shim := &delegateConfigReloadShim{delegate: a.delegate}
|
shim := &delegateConfigReloadShim{delegate: a.delegate}
|
||||||
|
// NOTE: this may require refactoring to remove a potential test race
|
||||||
a.delegate = shim
|
a.delegate = shim
|
||||||
if err := a.reloadConfigInternal(cfg2); err != nil {
|
if err := a.reloadConfigInternal(cfg2); err != nil {
|
||||||
t.Fatalf("got error %v want nil", err)
|
t.Fatalf("got error %v want nil", err)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -315,17 +314,6 @@ func TestIntentionCheck(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type testSrv struct {
|
|
||||||
delegate
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *testSrv) RPC(method string, args interface{}, reply interface{}) error {
|
|
||||||
return fmt.Errorf("rpc error making call: %w", errors.New("Intention not found"))
|
|
||||||
}
|
|
||||||
func (s *testSrv) Shutdown() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIntentionGetExact(t *testing.T) {
|
func TestIntentionGetExact(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("too slow for testing.Short")
|
t.Skip("too slow for testing.Short")
|
||||||
|
@ -333,12 +321,26 @@ func TestIntentionGetExact(t *testing.T) {
|
||||||
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
a := NewTestAgent(t, "")
|
hcl := `
|
||||||
defer a.Shutdown()
|
bootstrap = false
|
||||||
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
|
bootstrap_expect = 2
|
||||||
|
server = true
|
||||||
|
`
|
||||||
|
|
||||||
notfound := func(t *testing.T) {
|
a1 := NewTestAgent(t, hcl)
|
||||||
t.Helper()
|
a2 := NewTestAgent(t, hcl)
|
||||||
|
|
||||||
|
_, err := a1.JoinLAN([]string{
|
||||||
|
fmt.Sprintf("127.0.0.1:%d", a2.Config.SerfPortLAN),
|
||||||
|
}, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
testrpc.WaitForTestAgent(t, a1.RPC, "dc1")
|
||||||
|
testrpc.WaitForTestAgent(t, a2.RPC, "dc1")
|
||||||
|
testrpc.WaitForLeader(t, a1.RPC, "dc1")
|
||||||
|
testrpc.WaitForLeader(t, a2.RPC, "dc1")
|
||||||
|
|
||||||
|
run := func(t *testing.T, a *TestAgent) {
|
||||||
req, err := http.NewRequest("GET", "/v1/connect/intentions/exact?source=foo&destination=bar", nil)
|
req, err := http.NewRequest("GET", "/v1/connect/intentions/exact?source=foo&destination=bar", nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -351,15 +353,14 @@ func TestIntentionGetExact(t *testing.T) {
|
||||||
require.Nil(t, obj)
|
require.Nil(t, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("not found locally", func(t *testing.T) {
|
// One of these will be the leader and the other will be a follower so we
|
||||||
notfound(t)
|
// test direct RPC handling and RPC forwarding of errors at the same time.
|
||||||
})
|
for i, a := range []*TestAgent{a1, a2} {
|
||||||
|
t.Run(fmt.Sprintf("test agent %d of 2", i+1), func(t *testing.T) {
|
||||||
t.Run("not found by RPC", func(t *testing.T) {
|
run(t, a)
|
||||||
a.delegate = &testSrv{}
|
|
||||||
notfound(t)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIntentionPutExact(t *testing.T) {
|
func TestIntentionPutExact(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
|
|
Loading…
Reference in New Issue