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

Fails at parallel cleanup #5

Open
jovandeginste opened this issue Dec 21, 2020 · 0 comments · May be fixed by #6
Open

Fails at parallel cleanup #5

jovandeginste opened this issue Dec 21, 2020 · 0 comments · May be fixed by #6

Comments

@jovandeginste
Copy link

jovandeginste commented Dec 21, 2020

I like to use Filet for tests, to create temporary structures. I use the examples from your readme. Today I started running my tests in parallal (t.Parallel()), and had weird issues. It appears Filet does not support parallel testing...

Consider the following test file (main_test.go):

package main_test

import (
	"testing"
	"time"

	"github.com/Flaque/filet"
	"github.com/stretchr/testify/assert"
)

func TestMain(t *testing.T) {
	theTest(t)
}

func TestMain2(t *testing.T) {
	theTest(t)
}

func theTest(t *testing.T) {
	t.Parallel()

	defer filet.CleanUp(t)

	filet.TmpDir(t, "")

	time.Sleep(200 * time.Millisecond)
	assert.Len(t, filet.Files, 1)
}

So we have a trivially simple TmpDir being created and cleaned up, and have to test functions doing that. (It is important that we have at least two functions, since one function is never run in parallel with itself!)

When running the tests, we can control the parallelism:

$ go test -parallel 1 -count 10 main_test.go 
ok  	command-line-arguments	4.023s
$ go test -parallel 2 -count 10 main_test.go 
--- FAIL: TestMain2 (0.20s)
    main_test.go:27: 
        	Error Trace:	main_test.go:27
        	            				main_test.go:16
        	Error:      	"[/tmp/dir587929604 /tmp/dir894240147]" should have 1 item(s), but has 2
        	Test:       	TestMain2
[...]
FAIL
FAIL	command-line-arguments	2.021s
FAIL
jovandeginste added a commit to jovandeginste/filet that referenced this issue Dec 21, 2020
We create a new list of files per TestReporter. This needed a map, and
thus some helper functions to help with locking around the map.

This however changes the way you can access the `Files` array. You now
need to access it through the map key (see the README changes)

Fixes Flaque#5

Signed-off-by: Jo Vandeginste <[email protected]>
@jovandeginste jovandeginste linked a pull request Dec 21, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant