Skip to content

[WIP] use Go's native t.TempDir() in tests - #43346

Draft
thaJeztah wants to merge 5 commits into
moby:masterfrom
thaJeztah:testing_use_native_tempdir
Draft

[WIP] use Go's native t.TempDir() in tests#43346
thaJeztah wants to merge 5 commits into
moby:masterfrom
thaJeztah:testing_use_native_tempdir

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

follow-up to #43340

@thaJeztah thaJeztah added status/2-code-review area/testing kind/refactor PR's that refactor, or clean-up code labels Mar 7, 2022
@thaJeztah

This comment was marked as outdated.

@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from b5dfee2 to 6fba5cd Compare March 7, 2022 19:40
@tianon

tianon commented Mar 8, 2022

Copy link
Copy Markdown
Member

FWIW, this one helps me feel better about #43340 😅

Somehow using t.TempDir() feels less "magical" than having something else "automatically" adding things to Go's cleanup callbacks. 🤷 😇

@thaJeztah

Copy link
Copy Markdown
Member Author

Ah! I see you found this one as well; yes, I like t.TempDir(), and think we should phase-out the fs things for most uses (there are a couple of cases where it could still be useful, but we should have a close look if we need a utility for those, or if we could just as well use some (minimal) amount of "regular" go code in the test.

@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch 3 times, most recently from 7df50f3 to e17e815 Compare May 30, 2022 12:36
@thaJeztah

This comment was marked as outdated.

@thaJeztah

This comment was marked as outdated.

@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch 2 times, most recently from eecdcb1 to 77d808c Compare May 31, 2022 19:32
@thaJeztah

Copy link
Copy Markdown
Member Author

Getting closer; Windows is green now!

rootless is still failing on this one;

=== RUN   TestRemoveContainerWithRemovedVolume
    remove_test.go:39: assertion failed: error is not nil: Error response from daemon: error while creating mount source path '/tmp/TestRemoveContainerWithRemovedVolume1349239570/001': mkdir /tmp/TestRemoveContainerWithRemovedVolume1349239570/001: permission denied
--- FAIL: TestRemoveContainerWithRemovedVolume (0.11s)

Linux still has some failures;

=== RUN   TestSysctlOverride
    testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverride3702360633/001/mounts/shm: device or resource busy
--- FAIL: TestSysctlOverride (0.00s)

=== RUN   TestSysctlOverrideHost
    testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverrideHost226485533/001/mounts/shm: device or resource busy
--- FAIL: TestSysctlOverrideHost (0.00s)


=== RUN   TestDockerSuite/TestCpUnprivilegedUser
    docker_cli_cp_test.go:339: assertion failed: 
        Command:  su unprivilegeduser -c /usr/local/cli/docker cp 28f1d182a8d77c07c85dadf9ecbb4d7d0c9369042acfd66cec671a13423ebb60:test /tmp/TestDockerSuiteTestCpUnprivilegedUser2002826160/001
        ExitCode: 1
        Error:    exit status 1
        Stdout:   
        Stderr:   lstat /tmp/TestDockerSuiteTestCpUnprivilegedUser2002826160/001: permission denied
        
        
        Failures:
        ExitCode was 1 expected 0
        Expected no error
    --- FAIL: TestDockerSuite/TestCpUnprivilegedUser (0.71s)

=== RUN   TestDockerSuite/TestRunWithVolumesIsRecursive
    testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestDockerSuiteTestRunWithVolumesIsRecursive1156692230/001/tmpfs: device or resource busy
    --- FAIL: TestDockerSuite/TestRunWithVolumesIsRecursive (0.49s)


=== RUN   TestDockerSuite/TestSaveRepoWithMultipleImages
    docker_cli_save_load_test.go:228: assertion failed: error is not nil: exit status 1
    --- FAIL: TestDockerSuite/TestSaveRepoWithMultipleImages (1.12s)

@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch 4 times, most recently from c54fc40 to 1e44eff Compare June 1, 2022 09:52
@thaJeztah

This comment was marked as outdated.

@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch 3 times, most recently from b32d67d to 3a5426c Compare June 1, 2022 12:02
@thaJeztah

Copy link
Copy Markdown
Member Author

Remaining ones on Windows (still debugging this one);

=== FAIL: github.com/docker/docker/pkg/archive TestUntarPathWithInvalidDest (0.04s)
    archive_test.go:300: srcFile: C:\Users\CONTAI~1\AppData\Local\Temp\TestUntarPathWithInvalidDest212983393\001\src
    archive_test.go:301: tarFile: C:\Users\CONTAI~1\AppData\Local\Temp\TestUntarPathWithInvalidDest212983393\001\src.tar
    archive_test.go:306: srcFileU: /tmp/src
    archive_test.go:307: tarFileU: /tmp/src.tar
    archive_test.go:311: assertion failed: error is not nil: exit status 2: tar: Removing leading `/' from member names
        tar: /tmp/src: Cannot stat: No such file or directory
        tar: Exiting with failure status due to previous errors
        

=== FAIL: github.com/docker/docker/pkg/archive TestUntarPath (0.04s)
    archive_test.go:352: assertion failed: error is not nil: exit status 2: tar: /tmp/001/src.tar: Cannot open: No such file or directory
        tar: Error is not recoverable: exiting now
        

=== FAIL: github.com/docker/docker/pkg/archive TestUntarPathWithDestinationFile (0.04s)
    archive_test.go:384: assertion failed: error is not nil: exit status 2: tar: /tmp/001/src.tar: Cannot open: No such file or directory
        tar: Error is not recoverable: exiting now
        

=== FAIL: github.com/docker/docker/pkg/archive TestUntarPathWithDestinationSrcFileAsFolder (0.04s)
    archive_test.go:419: assertion failed: error is not nil: exit status 2: tar: /tmp/001/src.tar: Cannot open: No such file or directory
        tar: Error is not recoverable: exiting now

rootless:

=== RUN   TestRemoveContainerWithRemovedVolume
    remove_test.go:41: assertion failed: error is not nil: Error response from daemon: error while creating mount source path '/tmp/TestRemoveContainerWithRemovedVolume616613276/001': mkdir /tmp/TestRemoveContainerWithRemovedVolume616613276/001: permission denied
--- FAIL: TestRemoveContainerWithRemovedVolume (0.12s)

Linux:

=== RUN   TestDockerSuite/TestCpUnprivilegedUser
    docker_cli_cp_test.go:339: assertion failed: 
        Command:  su unprivilegeduser -c /usr/local/cli/docker cp b51b3e12fb57157451ae5515834a1341c73baefe74bcc5b89bb0ab50aff75a4f:test /tmp/TestDockerSuiteTestCpUnprivilegedUser4016000516/001
        ExitCode: 1
        Error:    exit status 1
        Stdout:   
        Stderr:   lstat /tmp/TestDockerSuiteTestCpUnprivilegedUser4016000516/001: permission denied
        
        
        Failures:
        ExitCode was 1 expected 0
        Expected no error
    --- FAIL: TestDockerSuite/TestCpUnprivilegedUser (0.64s)

=== RUN   TestDockerSuite/TestSaveRepoWithMultipleImages
    docker_cli_save_load_test.go:228: assertion failed: error is not nil: exit status 1
    --- FAIL: TestDockerSuite/TestSaveRepoWithMultipleImages (1.79s)

arm64 (different version of Linux?)

=== RUN   TestSysctlOverride
    oci_linux_test.go:61: umount /tmp/TestSysctlOverride2641690171/001/containers/fakecontainer/mount/shm, flags: 0x2: no such file or directory
    oci_linux_test.go:66: unlinkat /tmp/TestSysctlOverride2641690171/001/containers/fakecontainer/mounts/shm: device or resource busy
    testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverride2641690171/001/containers/fakecontainer/mounts/shm: device or resource busy
--- FAIL: TestSysctlOverride (0.00s)

=== RUN   TestSysctlOverrideHost
    oci_linux_test.go:61: umount /tmp/TestSysctlOverrideHost1378173456/001/containers/fakecontainer/mount/shm, flags: 0x2: no such file or directory
    oci_linux_test.go:66: unlinkat /tmp/TestSysctlOverrideHost1378173456/001/containers/fakecontainer/mounts/shm: device or resource busy
    testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverrideHost1378173456/001/containers/fakecontainer/mounts/shm: device or resource busy
--- FAIL: TestSysctlOverrideHost (0.00s)

@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from 9f60524 to 21378d0 Compare July 8, 2022 20:15
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from 21378d0 to f47a4a3 Compare September 3, 2022 21:28
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from f47a4a3 to c5ea5c5 Compare October 3, 2022 20:27
@thaJeztah

Copy link
Copy Markdown
Member Author

Failing on integration; rootless;

=== FAIL: amd64.integration.container TestRemoveContainerWithRemovedVolume (0.08s)
    remove_test.go:42: assertion failed: error is not nil: Error response from daemon: error while creating mount source path '/tmp/TestRemoveContainerWithRemovedVolume160279588/001': mkdir /tmp/TestRemoveContainerWithRemovedVolume160279588/001: permission denied

Failing on integration; systemd;

=== Failed
=== FAIL: amd64.integration.plugin.authz TestAuthZPluginV2RejectVolumeRequests (5.74s)
    authz_plugin_v2_test.go:99: assertion failed: error is not nil: Error response from daemon: plugin "riyaz/authz-no-volume-plugin:latest" not found

Failing unit-test:

=== FAIL: daemon TestSysctlOverrideHost (0.00s)
    oci_linux_test.go:60: umount /tmp/TestSysctlOverrideHost1847643613/001/containers/fakecontainer/mount/shm, flags: 0x2: no such file or directory
    oci_linux_test.go:65: unlinkat /tmp/TestSysctlOverrideHost1847643613/001/containers/fakecontainer/mounts/shm: device or resource busy
    testing.go:1097: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverrideHost1847643613/001/containers/fakecontainer/mounts/shm: device or resource busy

I may split this one up in smaller chunks, and leave the ones that need more attention.

@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch 3 times, most recently from 130dff9 to ea5ec46 Compare May 1, 2025 11:33
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch 4 times, most recently from 21d4083 to def1db8 Compare May 12, 2025 12:35
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from def1db8 to 4621af0 Compare May 12, 2025 15:49
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch 3 times, most recently from 2bcfc97 to 5ac8969 Compare July 13, 2025 14:33
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from 5ac8969 to bcf841e Compare July 14, 2026 07:30
@thaJeztah thaJeztah added this to the 29.7.0 milestone Jul 14, 2026
@vvoland vvoland modified the milestones: 29.7.0, 29.8.0 Jul 23, 2026
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from bcf841e to ea50358 Compare July 25, 2026 00:28
Copilot AI review requested due to automatic review settings July 25, 2026 00:28
Signed-off-by: Sebastiaan van Stijn <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    === RUN   TestSysctlOverride
        testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverride2860094781/001/mounts/shm: device or resource busy
    --- FAIL: TestSysctlOverride (0.00s)

fix panic in TestTmpfsDevShmNoDupMount

=== RUN   TestTmpfsDevShmNoDupMount
    --- FAIL: TestTmpfsDevShmNoDupMount (0.01s)
    panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1209078]
    goroutine 110 [running]:
    testing.tRunner.func1.2({0x180e0e0, 0x2af5180})
        /usr/local/go/src/testing/testing.go:1389 +0x1c8
    testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1392 +0x380
    panic({0x180e0e0, 0x2af5180})
        /usr/local/go/src/runtime/panic.go:838 +0x20c
    github.com/docker/docker/plugin.(*Store).getAllByCap(0x0?, {0x1aa19ca?, 0x4000963d48?})
        /go/src/github.com/docker/docker/plugin/store.go:76 +0x38
    github.com/docker/docker/plugin.(*Store).GetAllManagedPluginsByCap(...)
        /go/src/github.com/docker/docker/plugin/store.go:178
    github.com/docker/docker/daemon.(*Daemon).cleanupMetricsPlugins(0x4000169680)
        /go/src/github.com/docker/docker/daemon/metrics.go:113 +0x7c
    github.com/docker/docker/daemon.(*Daemon).Shutdown(0x4000169680)
        /go/src/github.com/docker/docker/daemon/daemon.go:1226 +0x5f8
    github.com/docker/docker/daemon.setupFakeDaemon.func1()
        /go/src/github.com/docker/docker/daemon/oci_linux_test.go:50 +0x34
    testing.(*common).Cleanup.func1()
        /usr/local/go/src/testing/testing.go:1034 +0x10c
    testing.(*common).runCleanup(0x4000ac44e0, 0x1dba270?)
        /usr/local/go/src/testing/testing.go:1203 +0x9c
    testing.tRunner.func2()
        /usr/local/go/src/testing/testing.go:1433 +0x30
    testing.tRunner(0x4000ac44e0, 0x1b5a968)
        /usr/local/go/src/testing/testing.go:1445 +0x13c
    created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:1486 +0x328

Signed-off-by: Sebastiaan van Stijn <[email protected]>

daemon: fix panic in test

=== Failed
=== FAIL: daemon TestTmpfsDevShmNoDupMount (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x199dc18]

goroutine 566 [running]:
testing.tRunner.func1.2({0x1bd9000, 0x33c1970})
	/usr/local/go/src/testing/testing.go:1632 +0x1bc
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1635 +0x334
panic({0x1bd9000?, 0x33c1970?})
	/usr/local/go/src/runtime/panic.go:791 +0x124
github.com/docker/docker/daemon.(*fakeImageService).Cleanup(0x0?)
	<autogenerated>:1 +0x28
github.com/docker/docker/daemon.(*Daemon).Shutdown(0x40006b26c8, {0x229def8, 0x3540a40})
	/go/src/github.com/docker/docker/daemon/daemon.go:1307 +0x644
github.com/docker/docker/daemon.setupFakeDaemon.func1()
	/go/src/github.com/docker/docker/daemon/oci_linux_test.go:62 +0x40
testing.(*common).Cleanup.func1()
	/usr/local/go/src/testing/testing.go:1176 +0xf8
testing.(*common).runCleanup(0x400057d040, 0x2270000?)
	/usr/local/go/src/testing/testing.go:1354 +0xd0
testing.tRunner.func2()
	/usr/local/go/src/testing/testing.go:1684 +0x2c
testing.tRunner(0x400057d040, 0x20429f8)
	/usr/local/go/src/testing/testing.go:1696 +0x110
created by testing.(*T).Run in goroutine 1
	/usr/local/go/src/testing/testing.go:1743 +0x314

Signed-off-by: Sebastiaan van Stijn <[email protected]>
    [2022-06-01T12:07:16.248Z] === FAIL: daemon TestSysctlOverride (0.00s)
    [2022-06-01T12:07:16.248Z]     testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverride982023519/001/mounts/shm: device or resource busy
    [2022-06-01T12:07:16.248Z]
    [2022-06-01T12:07:16.248Z] === FAIL: daemon TestSysctlOverrideHost (0.00s)
    [2022-06-01T12:07:16.248Z]     testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverrideHost881080732/001/mounts/shm: device or resource busy

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Failing on rootless; probably because the parent dir doesn't have
the right permissions;

    === FAIL: amd64.integration.container TestRemoveContainerWithRemovedVolume (0.07s)
        remove_test.go:41: assertion failed: error is not nil: Error response from daemon: error while creating mount source path '/tmp/TestRemoveContainerWithRemovedVolume1924909400/001/hostPath': mkdir /tmp/TestRemoveContainerWithRemovedVolume1924909400/001: permission denied

Signed-off-by: Sebastiaan van Stijn <[email protected]>
See if this works to fix;

    === FAIL: amd64.integration-cli TestDockerCLICpSuite/TestCpUnprivilegedUser (0.38s)
        docker_cli_cp_test.go:345: assertion failed:
            Command:  su unprivilegeduser -c /usr/local/cli/docker cp cbdd485903262d9de472b0ec6973675f8266209d5f4e32b2b9bd2759fc2d6794:test /tmp/TestDockerCLICpSuiteTestCpUnprivilegedUser231403686/001
            ExitCode: 1
            Error:    exit status 1
            Stdout:
            Stderr:   lstat /tmp/TestDockerCLICpSuiteTestCpUnprivilegedUser231403686/001: permission denied

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
thaJeztah force-pushed the testing_use_native_tempdir branch from ea50358 to d9d569f Compare July 25, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants