Skip to content

Fails at parallel cleanup #5

@jovandeginste

Description

@jovandeginste

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions