mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* 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>
37 lines
750 B
Go
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())
|
|
}
|