fix the problem
This commit is contained in:
parent
987571dd8c
commit
edae6a3ae8
@ -301,6 +301,7 @@ func (h *ChanHandler) Sub(ctx context.Context, i int, eq int) (<-chan int, error
|
|||||||
fmt.Println("ctxdone1", i, eq)
|
fmt.Println("ctxdone1", i, eq)
|
||||||
return
|
return
|
||||||
case <-wait:
|
case <-wait:
|
||||||
|
fmt.Println("CONSUMED WAIT: ", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
n += i
|
n += i
|
||||||
@ -416,8 +417,6 @@ func TestChanClosing(t *testing.T) {
|
|||||||
ctx1, cancel1 := context.WithCancel(context.Background())
|
ctx1, cancel1 := context.WithCancel(context.Background())
|
||||||
ctx2, cancel2 := context.WithCancel(context.Background())
|
ctx2, cancel2 := context.WithCancel(context.Background())
|
||||||
|
|
||||||
defer cancel2()
|
|
||||||
|
|
||||||
// sub
|
// sub
|
||||||
|
|
||||||
sub1, err := client.Sub(ctx1, 2, -1)
|
sub1, err := client.Sub(ctx1, 2, -1)
|
||||||
@ -436,9 +435,14 @@ func TestChanClosing(t *testing.T) {
|
|||||||
|
|
||||||
cancel1()
|
cancel1()
|
||||||
|
|
||||||
serverHandler.wait <- struct{}{}
|
|
||||||
require.Equal(t, 0, <-sub1)
|
require.Equal(t, 0, <-sub1)
|
||||||
|
time.Sleep(time.Millisecond * 50) // make sure the loop has exited (having a shared wait channel makes this annoying)
|
||||||
|
|
||||||
|
serverHandler.wait <- struct{}{}
|
||||||
require.Equal(t, 6, <-sub2)
|
require.Equal(t, 6, <-sub2)
|
||||||
|
|
||||||
|
cancel2()
|
||||||
|
require.Equal(t, 0, <-sub2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChanServerClose(t *testing.T) {
|
func TestChanServerClose(t *testing.T) {
|
||||||
|
@ -204,13 +204,14 @@ func (c *wsConn) handleOutChans() {
|
|||||||
if !ok {
|
if !ok {
|
||||||
// Output channel closed, cleanup, and tell remote that this happened
|
// Output channel closed, cleanup, and tell remote that this happened
|
||||||
|
|
||||||
|
id := caseToID[chosen-internal]
|
||||||
|
|
||||||
n := len(cases) - 1
|
n := len(cases) - 1
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
cases[chosen] = cases[n]
|
cases[chosen] = cases[n]
|
||||||
caseToID[chosen-internal] = caseToID[n-internal]
|
caseToID[chosen-internal] = caseToID[n-internal]
|
||||||
}
|
}
|
||||||
|
|
||||||
id := caseToID[chosen-internal]
|
|
||||||
cases = cases[:n]
|
cases = cases[:n]
|
||||||
caseToID = caseToID[:n-internal]
|
caseToID = caseToID[:n-internal]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user