From 7f501ce51278cf4e6e3ba0ad773369357162782f Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Thu, 3 Aug 2017 15:11:14 +0200 Subject: [PATCH] Race test, benchmarks, for drop resolution --- values/drop_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/values/drop_test.go b/values/drop_test.go index c14f76f..c55a238 100644 --- a/values/drop_test.go +++ b/values/drop_test.go @@ -22,3 +22,41 @@ func TestValue_drop(t *testing.T) { require.Equal(t, true, dv.Contains(ValueOf(testDrop{"foo"}))) require.Equal(t, 7, dv.PropertyValue(ValueOf("size")).Interface()) } + +func TestDrop_Resolve_race(t *testing.T) { + d := ValueOf(testDrop{1}) + values := make(chan int, 2) + for i := 0; i < 2; i++ { + go func() { values <- d.Int() }() + } + for i := 0; i < 2; i++ { + require.Equal(t, 1, <-values) + } +} + +func BenchmarkDrop_Resolve_1(b *testing.B) { + d := ValueOf(testDrop{1}) + for n := 0; n < b.N; n++ { + _ = d.Int() + } +} + +func BenchmarkDrop_Resolve_2(b *testing.B) { + for n := 0; n < b.N; n++ { + d := ValueOf(testDrop{1}) + _ = d.Int() + } +} + +func BenchmarkDrop_Resolve_3(b *testing.B) { + for n := 0; n < b.N; n++ { + d := ValueOf(testDrop{1}) + values := make(chan int, 10) + for i := cap(values); i > 0; i-- { + values <- d.Int() + } + for i := cap(values); i > 0; i-- { + _ = <-values + } + } +}