refactor drop tests, add test with dropped packets in both directions

This commit is contained in:
Marten Seemann
2017-09-11 12:08:19 +02:00
parent 792047a2c5
commit 142abb08b3
2 changed files with 46 additions and 30 deletions

View File

@@ -26,8 +26,30 @@ const (
DirectionIncoming Direction = iota
// DirectionOutgoing is the direction from the server to the client.
DirectionOutgoing
// DirectionBoth is both incoming and outgoing
DirectionBoth
)
func (d Direction) String() string {
switch d {
case DirectionIncoming:
return "incoming"
case DirectionOutgoing:
return "outgoing"
case DirectionBoth:
return "both"
default:
panic("unknown direction")
}
}
func (d Direction) Is(dir Direction) bool {
if d == DirectionBoth || dir == DirectionBoth {
return true
}
return d == dir
}
// DropCallback is a callback that determines which packet gets dropped.
type DropCallback func(dir Direction, packetCount uint64) bool