forked from samuel/go-zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test for recurring re-authing hang * Fix re-authing hang
- Loading branch information
1 parent
ec5ddaa
commit ff6eb7f
Showing
2 changed files
with
95 additions
and
5 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,55 @@ | ||
package zk | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestRecurringReAuthHang(t *testing.T) { | ||
sessionTimeout := 2 * time.Second | ||
|
||
finish := make(chan struct{}) | ||
defer close(finish) | ||
go func() { | ||
select { | ||
case <-finish: | ||
return | ||
case <-time.After(5 * sessionTimeout): | ||
panic("expected not hang") | ||
} | ||
}() | ||
|
||
zkC, err := StartTestCluster(2, ioutil.Discard, ioutil.Discard) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer zkC.Stop() | ||
|
||
conn, evtC, err := zkC.ConnectAll() | ||
if err != nil { | ||
panic(err) | ||
} | ||
for conn.state != StateHasSession { | ||
time.Sleep(50 * time.Millisecond) | ||
} | ||
|
||
go func() { | ||
for range evtC { | ||
} | ||
}() | ||
|
||
// Add auth. | ||
conn.creds = append(conn.creds, authCreds{"digest", []byte("test:test")}) | ||
|
||
currentServer := conn.server | ||
conn.debugCloseRecvLoop = true | ||
conn.debugReauthDone = make(chan struct{}) | ||
zkC.StopServer(currentServer) | ||
// wait connect to new zookeeper. | ||
for conn.server == currentServer && conn.state != StateHasSession { | ||
time.Sleep(100 * time.Millisecond) | ||
} | ||
|
||
<-conn.debugReauthDone | ||
} |