Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
raj-prince committed Sep 10, 2024
1 parent 047df14 commit 62a4f4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion storage/util/dynamic_delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func NewDelay(targetPercentile float64, increaseRate float64, initialDelay, minD
if initialDelay > maxDelay {
initialDelay = maxDelay
}
// See http://google3/net/rpc/contrib/hedged_call/dynamic_delay.h?l=35&rcl=194811090

// Compute increaseFactor and decreaseFactor such that:
// (increaseFactor ^ (1 - targetPercentile)) * (decreaseFactor ^ targetPercentile) = 1
increaseFactor := math.Exp(math.Log(2) / increaseRate)
if increaseFactor < 1.001 {
increaseFactor = 1.001
Expand Down
12 changes: 12 additions & 0 deletions storage/util/dynamic_delay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,15 @@ func TestOverflow(t *testing.T) {
t.Fatalf("unexpected d.Value: got %v, want %v", got, want)
}
}

func TestInvalidArgument(t *testing.T) {
_, err := NewDelay(1-0.1, 15, 1*time.Millisecond, 2*time.Hour, 1*time.Hour)
if err == nil {
t.Fatal("unexpected, should throw error as minDelay is greater than maxDelay")
}

_, err = NewDelay(1-0.1, 0, 1*time.Millisecond, 2*time.Hour, 1*time.Hour)
if err == nil {
t.Fatal("unexpected, should throw error as increaseRate can't be zero")
}
}

0 comments on commit 62a4f4b

Please sign in to comment.