Skip to content

Commit

Permalink
integration: debugging "TestDoubleBarrier"
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jun 14, 2018
1 parent f4fabc2 commit 5258b16
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion integration/v3_double_barrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package integration

import (
"fmt"
"os"
"testing"
"time"

Expand All @@ -24,71 +26,114 @@ import (

func TestDoubleBarrier(t *testing.T) {
clus := NewClusterV3(t, &ClusterConfig{Size: 3})
defer clus.Terminate(t)

os.Setenv("CLUSTER_DEBUG", "1")
defer func() {
os.Unsetenv("CLUSTER_DEBUG")
clus.Terminate(t)
}()

waiters := 10
fmt.Println("concurrency.NewSession 1")
session, err := concurrency.NewSession(clus.RandClient())
fmt.Println("concurrency.NewSession 2", err)
if err != nil {
t.Error(err)
}
defer session.Orphan()

fmt.Println("NewDoubleBarrier 1")
b := recipe.NewDoubleBarrier(session, "test-barrier", waiters)
fmt.Println("NewDoubleBarrier 2")
donec := make(chan struct{})
for i := 0; i < waiters-1; i++ {
go func() {
fmt.Println("concurrency.NewSession 3")
session, err := concurrency.NewSession(clus.RandClient())
fmt.Println("concurrency.NewSession 4")
if err != nil {
t.Error(err)
}
defer session.Orphan()

fmt.Println("NewDoubleBarrier 3")
bb := recipe.NewDoubleBarrier(session, "test-barrier", waiters)
fmt.Println("NewDoubleBarrier 4")

fmt.Println("Enter 1")
if err := bb.Enter(); err != nil {
fmt.Println("Enter 2", err)
t.Fatalf("could not enter on barrier (%v)", err)
}
fmt.Println("Enter 3")
donec <- struct{}{}
fmt.Println("Enter 4")
fmt.Println("Lease 1")
if err := bb.Leave(); err != nil {
fmt.Println("Lease 2", err)
t.Fatalf("could not leave on barrier (%v)", err)
}
fmt.Println("Lease 3")
donec <- struct{}{}
fmt.Println("Lease 4")
}()
}

fmt.Println("<-donec 1")
time.Sleep(10 * time.Millisecond)
select {
case <-donec:
fmt.Println("<-donec 2")
t.Fatalf("barrier did not enter-wait")
default:
fmt.Println("<-donec 3")
}
fmt.Println("<-donec 4")

fmt.Println("Enter 10")
if err := b.Enter(); err != nil {
fmt.Println("Enter 11", err)
t.Fatalf("could not enter last barrier (%v)", err)
}
fmt.Println("Enter 12")

timerC := time.After(time.Duration(waiters*100) * time.Millisecond)
for i := 0; i < waiters-1; i++ {
fmt.Println("waiters 1", i)
select {
case <-timerC:
fmt.Println("waiters 2", i)
t.Fatalf("barrier enter timed out")
case <-donec:
fmt.Println("waiters 3", i)
}
}

fmt.Println("donec 10-1")
time.Sleep(10 * time.Millisecond)
select {
case <-donec:
fmt.Println("donec 10-2")
t.Fatalf("barrier did not leave-wait")
default:
fmt.Println("donec 10-3")
}
fmt.Println("donec 10-4")

fmt.Println("Leave 1")
b.Leave()
fmt.Println("Leave 2")

fmt.Println("waiter 100-1")
timerC = time.After(time.Duration(waiters*100) * time.Millisecond)
for i := 0; i < waiters-1; i++ {
fmt.Println("waiter 100-2", i)
select {
case <-timerC:
fmt.Println("waiter 100-3", i)
t.Fatalf("barrier leave timed out")
case <-donec:
fmt.Println("waiter 100-4", i)
}
}
}
Expand Down

0 comments on commit 5258b16

Please sign in to comment.