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

chore: fix test tempdir generation #156

Merged
merged 1 commit into from
May 20, 2022

Conversation

saintube
Copy link
Member

@saintube saintube commented May 19, 2022

Signed-off-by: saintube saintube@foxmail.com

Ⅰ. Describe what this PR does

Fix a failure of unit tests on mac os (but not fails CI in GitHub Actions).

Ⅱ. Does this pull request fix one issue?

The issue exists after PR #151 merged.

$ go test ./pkg/runtime/...
E0519 18:25:43.411020   40030 runtime.go:57] failed to get docker endpoint, error: docker endpoint does not exist
E0519 18:25:43.412342   40030 runtime.go:88] failed to get containerd endpoint, error: containerd endpoint does not exist
E0519 18:25:43.413709   40030 runtime.go:57] failed to get docker endpoint, error: docker endpoint does not exist
E0519 18:25:43.415042   40030 runtime.go:63] failed to create docker runtime handler, error: Unix socket path "/var/folders/wf/0n_kt22d1ld90gfmbq0k8z5c0000gp/T/Test_GetRuntimeHandlertest_have_dockerRuntime_but_need_containerd758888209/001/var/run/docker.sock" is too long
--- FAIL: Test_GetRuntimeHandler (0.01s)
    --- FAIL: Test_GetRuntimeHandler/test_have_dockerRuntime_but_need_containerd (0.00s)
        runtime_test.go:136: 
                Error Trace:    runtime_test.go:136
                Error:          Not equal: 
                                expected: false
                                actual  : true
                Test:           Test_GetRuntimeHandler/test_have_dockerRuntime_but_need_containerd
                Messages:       Unix socket path "/var/folders/wf/0n_kt22d1ld90gfmbq0k8z5c0000gp/T/Test_GetRuntimeHandlertest_have_dockerRuntime_but_need_containerd758888209/001/var/run/docker.sock" is too long
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=0xf8 pc=0x1f25452]

goroutine 68 [running]:
testing.tRunner.func1.2({0x203dae0, 0x2f5f6b0})
        /Users/home/sdk/go1.17.9/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
        /Users/home/sdk/go1.17.9/src/testing/testing.go:1212 +0x218
panic({0x203dae0, 0x2f5f6b0})
        /Users/home/sdk/go1.17.9/src/runtime/panic.go:1038 +0x215
github.com/koordinator-sh/koordinator/pkg/runtime.Test_GetRuntimeHandler.func1(0xc000503380)
        /Users/home/go/src/github.com/koordinator-sh/koordinator/pkg/runtime/runtime_test.go:138 +0x4f2
testing.tRunner(0xc000503380, 0xc0002f1c20)
        /Users/home/sdk/go1.17.9/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
        /Users/home/sdk/go1.17.9/src/testing/testing.go:1306 +0x35a
FAIL    github.com/koordinator-sh/koordinator/pkg/runtime       1.527s
--- FAIL: Test_Docker_NewDockerRuntimeHandler (0.00s)
--- FAIL: Test_Docker_StopContainer (0.00s)
--- FAIL: Test_Docker_UpdateContainerResources (0.00s)
FAIL
FAIL    github.com/koordinator-sh/koordinator/pkg/runtime/handler       0.938s
?       github.com/koordinator-sh/koordinator/pkg/runtime/handler/mockclient    [no test files]
FAIL

Ⅲ. Describe how to verify it

make test gets no error

Ⅳ. Special notes for reviews

related issues:

@Juneezee
Copy link
Contributor

On MacOS, the maximum path length of Unix domain socket is 104 characters, see https://unix.stackexchange.com/a/367012/376279

According to the logs, it seems like t.TempDir() uses /var/folders/wf/0n_kt22d1ld90gfmbq0k8z5c0000gp/T insteads of /tmp on MacOS, which is why it is complaining that the socket path is too long.

@codecov-commenter
Copy link

codecov-commenter commented May 19, 2022

Codecov Report

Merging #156 (1a4a74f) into main (803298b) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head 1a4a74f differs from pull request most recent head 2f5073f. Consider uploading reports for the commit 2f5073f to get more accurate results

@@            Coverage Diff             @@
##             main     #156      +/-   ##
==========================================
+ Coverage   56.90%   56.92%   +0.02%     
==========================================
  Files          86       86              
  Lines        7882     7887       +5     
==========================================
+ Hits         4485     4490       +5     
  Misses       3004     3004              
  Partials      393      393              
Flag Coverage Δ
unittests 56.92% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/util/system/util_test_tool.go 56.66% <100.00%> (+2.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 803298b...2f5073f. Read the comment docs.

Copy link
Member

@jasonliu747 jasonliu747 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@saintube
Copy link
Member Author

On MacOS, the maximum path length of Unix domain socket is 104 characters, see https://unix.stackexchange.com/a/367012/376279

According to the logs, it seems like t.TempDir() uses /var/folders/wf/0n_kt22d1ld90gfmbq0k8z5c0000gp/T insteads of /tmp on MacOS, which is why it is complaining that the socket path is too long.

Yes. According to golang/go#21318 , this difference between OS platforms comes from os.TempDir(). We can set the environment variable $TMPDIR to change the base directory of os.TempDir().

Copy link
Member

@jasonliu747 jasonliu747 left a comment

Choose a reason for hiding this comment

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

/lgtm

@koordinator-bot koordinator-bot bot added the lgtm label May 19, 2022
Signed-off-by: saintube <saintube@foxmail.com>
Copy link
Member

@jasonliu747 jasonliu747 left a comment

Choose a reason for hiding this comment

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

/lgtm

@koordinator-bot koordinator-bot bot added the lgtm label May 19, 2022
@hormes
Copy link
Member

hormes commented May 20, 2022

/approve

@koordinator-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hormes, jasonliu747

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@koordinator-bot koordinator-bot bot merged commit 9f13a7b into koordinator-sh:main May 20, 2022
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.

None yet

5 participants