fix the problem

This commit is contained in:
Jeromy 2020-05-14 12:05:01 -07:00
parent 987571dd8c
commit edae6a3ae8
2 changed files with 9 additions and 4 deletions

View File

@ -301,6 +301,7 @@ func (h *ChanHandler) Sub(ctx context.Context, i int, eq int) (<-chan int, error
fmt.Println("ctxdone1", i, eq)
return
case <-wait:
fmt.Println("CONSUMED WAIT: ", i)
}
n += i
@ -416,8 +417,6 @@ func TestChanClosing(t *testing.T) {
ctx1, cancel1 := context.WithCancel(context.Background())
ctx2, cancel2 := context.WithCancel(context.Background())
defer cancel2()
// sub
sub1, err := client.Sub(ctx1, 2, -1)
@ -436,9 +435,14 @@ func TestChanClosing(t *testing.T) {
cancel1()
serverHandler.wait <- struct{}{}
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)
cancel2()
require.Equal(t, 0, <-sub2)
}
func TestChanServerClose(t *testing.T) {

View File

@ -204,13 +204,14 @@ func (c *wsConn) handleOutChans() {
if !ok {
// Output channel closed, cleanup, and tell remote that this happened
id := caseToID[chosen-internal]
n := len(cases) - 1
if n > 0 {
cases[chosen] = cases[n]
caseToID[chosen-internal] = caseToID[n-internal]
}
id := caseToID[chosen-internal]
cases = cases[:n]
caseToID = caseToID[:n-internal]