Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add square wave latency summand (#17)
* feat: add square wave summand * test: ensure that speedbump has started before dialing TCP in echo server test * docs: add square wave latency flags in cli arg reference * format: fix LatencyCfg struct initialization indent * refactor: simplify square wave formula
- Loading branch information
Showing
7 changed files
with
98 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package lib | ||
|
||
import "time" | ||
|
||
|
||
type squareLatencySummand struct { | ||
amplitude time.Duration | ||
period time.Duration | ||
} | ||
|
||
func (s squareLatencySummand) getLatency(elapsed time.Duration) time.Duration { | ||
return time.Duration( | ||
(4 * (elapsed / s.period) - 2 * ((2 * elapsed) / s.period) + 1) * s.amplitude, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package lib | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSquareLatencySummand(t *testing.T) { | ||
s := squareLatencySummand{ | ||
amplitude: time.Second * 2, | ||
period: time.Minute, | ||
} | ||
|
||
assert.Equal(t, s.getLatency(time.Duration(0)), time.Second * 2) | ||
assert.Equal(t, s.getLatency(time.Second * 15), time.Second * 2) | ||
assert.Equal(t, s.getLatency(time.Second * 30), time.Second * -2) | ||
assert.Equal(t, s.getLatency(time.Second * 45), time.Second * -2) | ||
assert.Equal(t, s.getLatency(time.Second * 60), time.Second * 2) | ||
assert.Equal(t, s.getLatency(time.Second * 84), time.Second * 2) | ||
assert.Equal(t, s.getLatency(time.Second * 90), time.Second * -2) | ||
} |