Mirror of Go implementation of WireGuard.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tai64n_test.go 582B

123456789101112131415161718192021222324252627282930
  1. /* SPDX-License-Identifier: MIT
  2. *
  3. * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
  4. */
  5. package tai64n
  6. import (
  7. "testing"
  8. "time"
  9. )
  10. /* Testing the essential property of the timestamp
  11. * as used by WireGuard.
  12. */
  13. func TestMonotonic(t *testing.T) {
  14. old := Now()
  15. for i := 0; i < 50; i++ {
  16. next := Now()
  17. if next.After(old) {
  18. t.Error("Whitening insufficient")
  19. }
  20. time.Sleep(time.Duration(whitenerMask)/time.Nanosecond + 1)
  21. next = Now()
  22. if !next.After(old) {
  23. t.Error("Not monotonically increasing on whitened nano-second scale")
  24. }
  25. old = next
  26. }
  27. }