Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup some tests + GetTLSConnectionState() race fix #2122

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,7 @@ func TestAccountSystemPermsWithGlobalAccess(t *testing.T) {
defer removeFile(t, conf)

s, _ := RunServerWithConfig(conf)
defer s.Shutdown()

// Make sure we can connect with no auth to global account as normal.
nc, err := nats.Connect(s.ClientURL())
Expand Down
5 changes: 5 additions & 0 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ func (c *client) GetOpts() *clientOpts {
// GetTLSConnectionState returns the TLS ConnectionState if TLS is enabled, nil
// otherwise. Implements the ClientAuth interface.
func (c *client) GetTLSConnectionState() *tls.ConnectionState {
c.mu.Lock()
defer c.mu.Unlock()
if c.nc == nil {
return nil
}
tc, ok := c.nc.(*tls.Conn)
if !ok {
return nil
Expand Down
1 change: 1 addition & 0 deletions server/jetstream_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6172,6 +6172,7 @@ func createJetStreamClusterExplicit(t *testing.T, clusterName string, numServers
}

func createJetStreamClusterWithTemplate(t *testing.T, tmpl string, clusterName string, numServers int) *cluster {
t.Helper()
const startClusterPort = 22332
return createJetStreamCluster(t, tmpl, clusterName, _EMPTY_, numServers, startClusterPort, true)
}
Expand Down
1 change: 1 addition & 0 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9103,6 +9103,7 @@ func TestJetStreamPushConsumersPullError(t *testing.T) {
}

nc, js := jsClientConnect(t, s)
defer nc.Close()

if _, err := js.AddStream(&nats.StreamConfig{Name: "TEST"}); err != nil {
t.Fatalf("Unexpected error: %v", err)
Expand Down
6 changes: 6 additions & 0 deletions server/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5545,7 +5545,9 @@ func TestJWTAccountProtectedImport(t *testing.T) {
s, _ := RunServerWithConfig(cf)
defer s.Shutdown()
ncExp := natsConnect(t, s.ClientURL(), createUserCreds(t, s, exportKp))
defer ncExp.Close()
ncImp := natsConnect(t, s.ClientURL(), createUserCreds(t, s, importKp))
defer ncImp.Close()
t.Run("service", func(t *testing.T) {
sub, err := ncExp.Subscribe("service.*", func(msg *nats.Msg) {
msg.Respond([]byte("world"))
Expand Down Expand Up @@ -5580,7 +5582,9 @@ func TestJWTAccountProtectedImport(t *testing.T) {
s, _ := RunServerWithConfig(cf)
defer s.Shutdown()
ncExp := natsConnect(t, s.ClientURL(), createUserCreds(t, s, exportKp))
defer ncExp.Close()
ncImp := natsConnect(t, s.ClientURL(), createUserCreds(t, s, importKp))
defer ncImp.Close()
t.Run("service", func(t *testing.T) {
sub, err := ncExp.Subscribe("service.*", func(msg *nats.Msg) {
msg.Respond([]byte("world"))
Expand Down Expand Up @@ -5635,7 +5639,9 @@ func TestJWTAccountProtectedImport(t *testing.T) {
updateJwt(t, s.ClientURL(), sysUsrCreds, importJWT, 1)
updateJwt(t, s.ClientURL(), sysUsrCreds, exportJWTOff, 1)
ncExp := natsConnect(t, s.ClientURL(), createUserCreds(t, s, exportKp))
defer ncExp.Close()
ncImp := natsConnect(t, s.ClientURL(), createUserCreds(t, s, importKp))
defer ncImp.Close()
msgChan := make(chan *nats.Msg, 4)
defer close(msgChan)
// ensure service passes
Expand Down
1 change: 1 addition & 0 deletions server/leafnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,7 @@ func TestLeafNodeWSBasic(t *testing.T) {
checkSubInterest(t, ln, globalAccountName, "foo", time.Second)

nc2 := natsConnect(t, ln.ClientURL())
defer nc2.Close()
msg1Payload := make([]byte, 512)
for i := 0; i < len(msg1Payload); i++ {
msg1Payload[i] = 'A'
Expand Down
2 changes: 1 addition & 1 deletion server/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ func TestParseExport(t *testing.T) {
nc1 := connect("u1")
defer nc1.Close()
nc2 := connect("u2")
defer nc1.Close()
defer nc2.Close()
subscribe := func(nc *nats.Conn, msgs int, subj string) (*sync.WaitGroup, *nats.Subscription) {
wg := sync.WaitGroup{}
wg.Add(msgs)
Expand Down
1 change: 0 additions & 1 deletion test/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ func TestTLSRoutesCertificateImplicitAllowFail(t *testing.T) {
}

func testTLSRoutesCertificateImplicitAllow(t *testing.T, pass bool) {
t.Helper()
// Base config for the servers
cfg := createFile(t, "cfg")
defer removeFile(t, cfg.Name())
Expand Down