forked from Shopify/toxiproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoxic_timeout.go
More file actions
39 lines (33 loc) · 790 Bytes
/
toxic_timeout.go
File metadata and controls
39 lines (33 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import "time"
// The TimeoutToxic stops any data from flowing through, and will close the connection after a timeout.
// If the timeout is set to 0, then the connection will not be closed.
type TimeoutToxic struct {
Enabled bool `json:"enabled"`
// Times in milliseconds
Timeout int64 `json:"timeout"`
}
func (t *TimeoutToxic) Name() string {
return "timeout"
}
func (t *TimeoutToxic) IsEnabled() bool {
return t.Enabled
}
func (t *TimeoutToxic) SetEnabled(enabled bool) {
t.Enabled = enabled
}
func (t *TimeoutToxic) Pipe(stub *ToxicStub) {
timeout := time.Duration(t.Timeout) * time.Millisecond
if timeout > 0 {
select {
case <-time.After(timeout):
stub.Close()
return
case <-stub.interrupt:
return
}
} else {
<-stub.interrupt
return
}
}