aboutsummaryrefslogtreecommitdiffstats
path: root/tai64n/tai64n.go
diff options
context:
space:
mode:
authorDmytro Shynkevych <dmytro@tailscale.com>2020-05-05 18:37:54 -0400
committerDavid Crawshaw <crawshaw@tailscale.com>2020-05-06 16:01:48 +1000
commitf60b3919bec891d37652edc25c48d83345d9885c (patch)
treeeb4156d4891e71dc8f244e059062bc6527057396 /tai64n/tai64n.go
parentmain: now that we're upstreamed, relax Linux warning (diff)
downloadwireguard-go-f60b3919bec891d37652edc25c48d83345d9885c.tar.xz
wireguard-go-f60b3919bec891d37652edc25c48d83345d9885c.zip
tai64n: make the test deterministic
In the presence of preemption, the current test may fail transiently. This uses static test data instead to ensure consistent behavior. Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
Diffstat (limited to 'tai64n/tai64n.go')
-rw-r--r--tai64n/tai64n.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/tai64n/tai64n.go b/tai64n/tai64n.go
index fb32d0c..2838f4f 100644
--- a/tai64n/tai64n.go
+++ b/tai64n/tai64n.go
@@ -17,16 +17,19 @@ const whitenerMask = uint32(0x1000000 - 1)
type Timestamp [TimestampSize]byte
-func Now() Timestamp {
+func stamp(t time.Time) Timestamp {
var tai64n Timestamp
- now := time.Now()
- secs := base + uint64(now.Unix())
- nano := uint32(now.Nanosecond()) &^ whitenerMask
+ secs := base + uint64(t.Unix())
+ nano := uint32(t.Nanosecond()) &^ whitenerMask
binary.BigEndian.PutUint64(tai64n[:], secs)
binary.BigEndian.PutUint32(tai64n[8:], nano)
return tai64n
}
+func Now() Timestamp {
+ return stamp(time.Now())
+}
+
func (t1 Timestamp) After(t2 Timestamp) bool {
return bytes.Compare(t1[:], t2[:]) > 0
}