-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This can happen when one other node in the cluster such as a client is unable to communicate with the leader server and sees it as failed. When that happens its failing status eventually gets propagated to the other servers in the cluster and eventually this can result in RPCs returning “No cluster leader” error. That error is misleading and unhelpful for determing the root cause of the issue as its not raft stability but rather and client -> server networking issue. Therefore this commit will add a new error that will be returned in that case to differentiate between the two cases.
- Loading branch information
Showing
5 changed files
with
174 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package consul | ||
|
||
import ( | ||
"net/rpc" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/consul/testrpc" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testClusterConfig struct { | ||
Datacenter string | ||
Servers int | ||
Clients int | ||
ServerConf func(*Config) | ||
ClientConf func(*Config) | ||
|
||
ServerWait func(*testing.T, *Server) | ||
ClientWait func(*testing.T, *Client) | ||
} | ||
|
||
type testCluster struct { | ||
Servers []*Server | ||
ServerCodecs []rpc.ClientCodec | ||
Clients []*Client | ||
} | ||
|
||
func newTestCluster(t *testing.T, conf *testClusterConfig) *testCluster { | ||
t.Helper() | ||
|
||
require.NotNil(t, conf) | ||
cluster := testCluster{} | ||
|
||
// create the servers | ||
for i := 0; i < conf.Servers; i++ { | ||
dir, srv := testServerWithConfig(t, func(c *Config) { | ||
if conf.Datacenter != "" { | ||
c.Datacenter = conf.Datacenter | ||
} | ||
c.Bootstrap = false | ||
c.BootstrapExpect = conf.Servers | ||
|
||
if conf.ServerConf != nil { | ||
conf.ServerConf(c) | ||
} | ||
}) | ||
t.Cleanup(func() { os.RemoveAll(dir) }) | ||
t.Cleanup(func() { srv.Shutdown() }) | ||
|
||
cluster.Servers = append(cluster.Servers, srv) | ||
|
||
codec := rpcClient(t, srv) | ||
|
||
cluster.ServerCodecs = append(cluster.ServerCodecs, codec) | ||
t.Cleanup(func() { codec.Close() }) | ||
|
||
if i > 0 { | ||
joinLAN(t, srv, cluster.Servers[0]) | ||
} | ||
} | ||
|
||
waitForLeaderEstablishment(t, cluster.Servers...) | ||
if conf.ServerWait != nil { | ||
for _, srv := range cluster.Servers { | ||
conf.ServerWait(t, srv) | ||
} | ||
} | ||
|
||
// create the clients | ||
for i := 0; i < conf.Clients; i++ { | ||
dir, client := testClientWithConfig(t, func(c *Config) { | ||
if conf.Datacenter != "" { | ||
c.Datacenter = conf.Datacenter | ||
} | ||
if conf.ClientConf != nil { | ||
conf.ClientConf(c) | ||
} | ||
}) | ||
|
||
t.Cleanup(func() { os.RemoveAll(dir) }) | ||
t.Cleanup(func() { client.Shutdown() }) | ||
|
||
if len(cluster.Servers) > 0 { | ||
joinLAN(t, client, cluster.Servers[0]) | ||
} | ||
|
||
cluster.Clients = append(cluster.Clients, client) | ||
} | ||
|
||
for _, client := range cluster.Clients { | ||
if conf.ClientWait != nil { | ||
conf.ClientWait(t, client) | ||
} else { | ||
testrpc.WaitForTestAgent(t, client.RPC, client.config.Datacenter) | ||
} | ||
} | ||
|
||
return &cluster | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters