This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
forked from samuel/go-zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mesosphere/mh/reauth
Fix re-auth hang.
- Loading branch information
Showing
2 changed files
with
158 additions
and
20 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
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,65 @@ | ||
package zk | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestRecurringReAuthHang(t *testing.T) { | ||
zkC, err := StartTestCluster(3, ioutil.Discard, ioutil.Discard) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer zkC.Stop() | ||
|
||
conn, evtC, err := zkC.ConnectAll() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
ctx, cancel := context.WithDeadline( | ||
context.Background(), time.Now().Add(5*time.Second)) | ||
defer cancel() | ||
for conn.State() != StateHasSession { | ||
time.Sleep(50 * time.Millisecond) | ||
|
||
select { | ||
case <-ctx.Done(): | ||
t.Fatal("Failed to connect to ZK") | ||
default: | ||
} | ||
} | ||
|
||
go func() { | ||
for range evtC { | ||
} | ||
}() | ||
|
||
// Add auth. | ||
conn.credsMu.Lock() | ||
conn.creds = append(conn.creds, authCreds{"digest", []byte("test:test")}) | ||
conn.credsMu.Unlock() | ||
|
||
currentServer := conn.Server() | ||
conn.setDebugCloseRecvLoop(true) | ||
zkC.StopServer(currentServer) | ||
|
||
// wait connect to new zookeeper. | ||
ctx, cancel = context.WithDeadline( | ||
context.Background(), time.Now().Add(5*time.Second)) | ||
defer cancel() | ||
for conn.Server() == currentServer && conn.State() != StateHasSession { | ||
time.Sleep(100 * time.Millisecond) | ||
|
||
select { | ||
case <-ctx.Done(): | ||
t.Fatal("Failed to reconnect ZK next server") | ||
default: | ||
} | ||
} | ||
|
||
<-conn.debugReauthDone | ||
conn.Close() | ||
} |