Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf30c7460c |
@@ -494,37 +494,34 @@ func TestStatsAnswerGivesConnectionDurationInSeconds(t *testing.T) {
|
|||||||
// TestStreamDurationsCountSeconds checks that the uptime and the connection
|
// TestStreamDurationsCountSeconds checks that the uptime and the connection
|
||||||
// duration of a stream that connected 90 seconds ago are both 90. A stream
|
// duration of a stream that connected 90 seconds ago are both 90. A stream
|
||||||
// that has never connected has an uptime of 0, and one that is not connected
|
// that has never connected has an uptime of 0, and one that is not connected
|
||||||
// has no connection duration. The test runs in a synctest bubble, whose clock
|
// has no connection duration.
|
||||||
// is fake, so a stall on the host does not add to the 90 seconds.
|
|
||||||
func TestStreamDurationsCountSeconds(t *testing.T) {
|
func TestStreamDurationsCountSeconds(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
synctest.Test(t, func(t *testing.T) {
|
const connectedFor = 90 * time.Second
|
||||||
const connectedFor = 90 * time.Second
|
|
||||||
|
|
||||||
connectedSince := time.Now().Add(-connectedFor)
|
connectedSince := time.Now().Add(-connectedFor)
|
||||||
want := int64(connectedFor / time.Second)
|
want := int64(connectedFor / time.Second)
|
||||||
|
|
||||||
if got := uptimeSeconds(connectedSince); got != want {
|
if got := uptimeSeconds(connectedSince); got != want {
|
||||||
t.Errorf("uptimeSeconds = %d, want %d", got, want)
|
t.Errorf("uptimeSeconds = %d, want %d", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got := uptimeSeconds(time.Time{}); got != 0 {
|
if got := uptimeSeconds(time.Time{}); got != 0 {
|
||||||
t.Errorf("uptimeSeconds before any connection = %d, want 0", got)
|
t.Errorf("uptimeSeconds before any connection = %d, want 0", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch got := connectionDurationSeconds(true, connectedSince); {
|
switch got := connectionDurationSeconds(true, connectedSince); {
|
||||||
case got == nil:
|
case got == nil:
|
||||||
t.Errorf("connectionDurationSeconds = nil, want %d", want)
|
t.Errorf("connectionDurationSeconds = nil, want %d", want)
|
||||||
case *got != want:
|
case *got != want:
|
||||||
t.Errorf("connectionDurationSeconds = %d, want %d", *got, want)
|
t.Errorf("connectionDurationSeconds = %d, want %d", *got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got := connectionDurationSeconds(false, connectedSince); got != nil {
|
if got := connectionDurationSeconds(false, connectedSince); got != nil {
|
||||||
t.Errorf("connectionDurationSeconds while not connected = %d, want nil",
|
t.Errorf("connectionDurationSeconds while not connected = %d, want nil",
|
||||||
*got)
|
*got)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newTestTable returns a routing table that holds a route for testPrefixV4,
|
// newTestTable returns a routing table that holds a route for testPrefixV4,
|
||||||
|
|||||||
Reference in new issue
Block a user