Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random index out of range [0] with length 0 error in some tests #113

Open
MarkKremer opened this issue Mar 29, 2021 · 0 comments
Open

Random index out of range [0] with length 0 error in some tests #113

MarkKremer opened this issue Mar 29, 2021 · 0 comments

Comments

@MarkKremer
Copy link
Contributor

MarkKremer commented Mar 29, 2021

Follow up on #108 on why the test failed randomly. I got the following error:

--- FAIL: TestFloat64Engine_makeArray (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 128 [running]:
testing.tRunner.func1.1(0x14a0a80, 0xc000244080)
	/opt/hostedtoolcache/go/1.14.15/x64/src/testing/testing.go:999 +0x461
testing.tRunner.func1(0xc00045c240)
	/opt/hostedtoolcache/go/1.14.15/x64/src/testing/testing.go:1002 +0x606
panic(0x14a0a80, 0xc000244080)
	/opt/hostedtoolcache/go/1.14.15/x64/src/runtime/panic.go:975 +0x3e3
gorgonia.org/tensor.(*array).Uintptr(...)
	/home/runner/work/tensor/tensor/array.go:158
gorgonia.org/tensor.array.Data(0x1e438f0, 0x0, 0x0, 0x169fc40, 0x13eb260, 0x13f33f7, 0x13f33e0)
	/home/runner/work/tensor/tensor/array.go:167 +0x211
gorgonia.org/tensor.TestFloat64Engine_makeArray.func1(0x0, 0x0)
	/home/runner/work/tensor/tensor/defaultenginefloat64_test.go:26 +0x199
reflect.Value.call(0x140fb00, 0xc000466040, 0x13, 0x14f71eb, 0x4, 0xc0001b8000, 0x1, 0x1, 0x49d7c2, 0x53aa60, ...)
	/opt/hostedtoolcache/go/1.14.15/x64/src/reflect/value.go:460 +0x967
reflect.Value.Call(0x140fb00, 0xc000466040, 0x13, 0xc0001b8000, 0x1, 0x1, 0xc000188000, 0x0, 0x0)
	/opt/hostedtoolcache/go/1.14.15/x64/src/reflect/value.go:321 +0xd4
testing/quick.Check(0x140fb00, 0xc000466040, 0x0, 0x4dce27, 0x47817b)
	/opt/hostedtoolcache/go/1.14.15/x64/src/testing/quick/quick.go:290 +0x27a
gorgonia.org/tensor.TestFloat64Engine_makeArray(0xc00045c240)
	/home/runner/work/tensor/tensor/defaultenginefloat64_test.go:38 +0xac
testing.tRunner(0xc00045c240, 0x1534a08)
	/opt/hostedtoolcache/go/1.14.15/x64/src/testing/testing.go:1050 +0x1ec
created by testing.(*T).Run
	/opt/hostedtoolcache/go/1.14.15/x64/src/testing/testing.go:1095 +0x538

After looking into it, it seems that quick.Check passes a random value for the size parameter to the test function. In this specific instance that random value was 0. This size is then used to create an array. And some of the functions don't work if the array has a length of 0.

Fun fact: this has a 1 in 65536 chance of occurring. This happened to me twice now. I don't think the chances are evenly distributed.

This can be fixed two ways:

  • Make array work with 0 as a size. (probably hard to do while keeping it efficient)
  • Make sure the tests don't pass in 0. And make sure that the makeArray doesn't get called with 0 (or less) as its size argument by returning an error earlier.

I think there are some other tests that can cause similar errors.

I am not working on fixing this at the moment so feel free to work on this issue if you're interested.

@MarkKremer MarkKremer changed the title Flaky test Random index out of range [0] with length 0 error in some tests Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant