-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27feb17
commit 63190cb
Showing
8 changed files
with
172 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package emitter | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/Fantom-foundation/go-opera/inter" | ||
"github.com/Fantom-foundation/go-opera/opera" | ||
) | ||
|
||
func TestGetEmitterIntervalLimit_IsOffWhenIntervalIsZero(t *testing.T) { | ||
ms := time.Microsecond | ||
rules := opera.EmitterRules{ | ||
Interval: 0, | ||
StallThreshold: inter.Timestamp(200 * ms), | ||
} | ||
for _, delay := range []time.Duration{0, 100 * ms, 199 * ms, 200 * ms, 201 * ms} { | ||
_, enabled := getEmitterIntervalLimit(rules, delay) | ||
if enabled { | ||
t.Fatal("should be disabled") | ||
} | ||
} | ||
} | ||
|
||
func TestGetEmitterIntervalLimit_SwitchesToStallIfDelayed(t *testing.T) { | ||
ms := time.Millisecond | ||
regular := 100 * ms | ||
stallThreshold := 200 * ms | ||
stalled := 300 * ms | ||
|
||
rules := opera.EmitterRules{ | ||
Interval: inter.Timestamp(regular), | ||
StallThreshold: inter.Timestamp(stallThreshold), | ||
StalledInterval: inter.Timestamp(stalled), | ||
} | ||
|
||
for _, delay := range []time.Duration{0, 100 * ms, 199 * ms, 200 * ms, 201 * ms, 60 * time.Minute} { | ||
got, enabled := getEmitterIntervalLimit(rules, delay) | ||
if !enabled { | ||
t.Fatalf("should be enabled for delay %v", delay) | ||
} | ||
want := regular | ||
if delay > stallThreshold { | ||
want = stalled | ||
} | ||
if want != got { | ||
t.Errorf("for delay %v, want %v, got %v", delay, want, got) | ||
} | ||
} | ||
} |
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