/
host_test.go
39 lines (31 loc) · 1008 Bytes
/
host_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package metrics
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestHostSample_CachedNtpOffset(t *testing.T) {
timeout := uint(5)
interval := uint(15)
ntpMonitor := NewNtp([]string{"one"}, timeout, interval)
ntpMonitor.ntpQuery = ntpQueryMock([]ntpResp{
{
resp: buildValidNtpResponse(50 * time.Millisecond),
err: nil,
},
}...)
hostMonitor := NewHostMonitor(ntpMonitor)
expectedOffset := (50 * time.Millisecond).Seconds()
expectedNtpSample := &expectedOffset
// valid ntp response
ntpMonitor.ntpQuery = ntpQueryMock([]ntpResp{{buildValidNtpResponse(50 * time.Millisecond), nil}}...)
sample, err := hostMonitor.Sample()
assert.Nil(t, err)
assert.Equal(t, expectedNtpSample, sample.NtpOffset)
// query inside interval should return cached value
sample, err = hostMonitor.Sample()
assert.Nil(t, err)
assert.Equal(t, expectedNtpSample, sample.NtpOffset)
}