atomicduration_test.go 535 B

12345678910111213141516171819
  1. package syncx
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestAtomicDuration(t *testing.T) {
  8. d := ForAtomicDuration(time.Duration(100))
  9. assert.Equal(t, time.Duration(100), d.Load())
  10. d.Set(time.Duration(200))
  11. assert.Equal(t, time.Duration(200), d.Load())
  12. assert.True(t, d.CompareAndSwap(time.Duration(200), time.Duration(300)))
  13. assert.Equal(t, time.Duration(300), d.Load())
  14. assert.False(t, d.CompareAndSwap(time.Duration(200), time.Duration(400)))
  15. assert.Equal(t, time.Duration(300), d.Load())
  16. }