Skip to content

Commit

Permalink
timeout toxic drops more than just the first segment
Browse files Browse the repository at this point in the history
  • Loading branch information
jpittis committed Apr 4, 2017
1 parent 476c3aa commit 7cda467
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions toxics/timeout.go
Expand Up @@ -24,11 +24,13 @@ func (t *TimeoutToxic) Pipe(stub *ToxicStub) {
}
}
} else {
select {
case <-stub.Interrupt:
return
case <-stub.Input:
// Drop the data on the ground.
for {
select {
case <-stub.Interrupt:
return
case <-stub.Input:
// Drop the data on the ground.
}
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions toxics/timeout_test.go
Expand Up @@ -70,16 +70,17 @@ func WithEstablishedProxy(t *testing.T, f func(net.Conn, net.Conn, *toxiproxy.Pr
func TestTimeoutToxicDoesNotCauseHang(t *testing.T) {
WithEstablishedProxy(t, func(conn, _ net.Conn, proxy *toxiproxy.Proxy) {
proxy.Toxics.AddToxicJson(ToxicToJson(t, "might_block", "latency", "upstream", &toxics.LatencyToxic{Latency: 10}))
proxy.Toxics.AddToxicJson(ToxicToJson(t, "to_delete", "timeout", "upstream", &toxics.TimeoutToxic{Timeout: 0}))
proxy.Toxics.AddToxicJson(ToxicToJson(t, "timeout", "timeout", "upstream", &toxics.TimeoutToxic{Timeout: 0}))

_, err := conn.Write([]byte("hello"))
if err != nil {
t.Fatal("Unable to write to proxy", err)
for i := 0; i < 5; i++ {
_, err := conn.Write([]byte("hello"))
if err != nil {
t.Fatal("Unable to write to proxy", err)
}
time.Sleep(200 * time.Millisecond) // Shitty sync waiting for latency toxi to get data.
}

time.Sleep(1 * time.Second) // Shitty sync waiting for latency toxi to get data.

err = testhelper.TimeoutAfter(time.Second, func() {
err := testhelper.TimeoutAfter(time.Second, func() {
proxy.Toxics.RemoveToxic("might_block")
})
if err != nil {
Expand Down

0 comments on commit 7cda467

Please sign in to comment.