Files
gocryptotrader/exchanges/nonce/nonce_test.go
Ryan O'Hara-Reid e823f9edd8 request/nonce: Refactor to simplify package and prevent consecutive mutex lock calls when accessing/setting nonce values (#1506)
* improv. timed mutex

* Add all protection back in and jankyness because races. :'(

* Add intial benchmarkeroos

* Add master benchmarks

* goodness me

* what?

* what again?

* glorious: nits

* just a swaperino instead

* clean up package nonce so that we only need to aquire mutex once

* unlock before checking master

* commentary

* wha

* more comment

* ch comment

* nonce: Allow for broad customisation externally with a ~2ns overhead

* glorious: nits maybe works?

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
2024-04-12 16:54:21 +10:00

37 lines
750 B
Go

package nonce
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetAndIncrement(t *testing.T) {
var nonce Nonce
n1 := nonce.GetAndIncrement(Unix)
assert.NotZero(t, n1)
n2 := nonce.GetAndIncrement(Unix)
assert.NotZero(t, n2)
assert.NotEqual(t, n1, n2)
var nonce2 Nonce
n3 := nonce2.GetAndIncrement(UnixNano)
assert.NotZero(t, n3)
n4 := nonce2.GetAndIncrement(UnixNano)
assert.NotZero(t, n4)
assert.NotEqual(t, n3, n4)
assert.NotEqual(t, n1, n3)
assert.NotEqual(t, n2, n4)
}
func TestString(t *testing.T) {
var nonce Nonce
nonce.n = 12312313131
got := nonce.GetAndIncrement(Unix)
assert.Equal(t, "12312313131", got.String())
got = nonce.GetAndIncrement(Unix)
assert.Equal(t, "12312313132", got.String())
}