-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathroutine_api_test.go
More file actions
48 lines (40 loc) · 921 Bytes
/
routine_api_test.go
File metadata and controls
48 lines (40 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package routine
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGoid(t *testing.T) {
t.Log(Goid())
}
func TestGoStorage(t *testing.T) {
var variable = "hello world"
stg := NewLocalStorage()
stg.Set(variable)
Go(func() {
v := stg.Get()
assert.True(t, v != nil && v.(string) == variable)
})
nap()
stg2 := NewLocalStorage()
stg2.Set(int64(100))
v := stg.Get()
assert.True(t, v != nil && v.(string) == variable)
v = stg2.Get()
assert.True(t, v != nil && v.(int64) == 100)
}
// BenchmarkGoid-12 1000000000 1.036 ns/op 0 B/op 0 allocs/op
func BenchmarkGoid(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = Goid()
}
}
// BenchmarkCurr-12 45119158 26.00 ns/op 16 B/op 1 allocs/op
func BenchmarkCurr(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = GetG()
}
}