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

ARROW-17340: [Go] Use T.TempDir to create temporary test directory #13816

Merged
merged 2 commits into from Aug 8, 2022
Merged

ARROW-17340: [Go] Use T.TempDir to create temporary test directory #13816

merged 2 commits into from Aug 8, 2022

Conversation

Juneezee
Copy link
Contributor

@Juneezee Juneezee commented Aug 8, 2022

A testing cleanup.

This pull request replaces ioutil.TempDir with t.TempDir. We can use the T.TempDir function from the testing package to create temporary directory. The directory created by T.TempDir is automatically removed when the test and all its subtests complete.

This saves us at least 2 lines (error check, and cleanup) on every instance, or in some cases adds cleanup that we forgot.

Reference: https://pkg.go.dev/testing#T.TempDir

func TestFoo(t *testing.T) {
	// before
	tmpDir, err := ioutil.TempDir("", "")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmpDir)

	// now
	tmpDir := t.TempDir()
}

This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
@github-actions
Copy link

github-actions bot commented Aug 8, 2022

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on JIRA? https://issues.apache.org/jira/browse/ARROW

Opening JIRAs ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename pull request title in the following format?

ARROW-${JIRA_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@zeroshade zeroshade changed the title [Go] Use T.TempDir to create temporary test directory ARROW-17340: [Go] Use T.TempDir to create temporary test directory Aug 8, 2022
Copy link
Member

@zeroshade zeroshade left a comment

Choose a reason for hiding this comment

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

Thanks @Juneezee this is definitely an improvement!

I'll merge this after all the tests succeed. 😄

@github-actions
Copy link

github-actions bot commented Aug 8, 2022

@zeroshade
Copy link
Member

zeroshade commented Aug 8, 2022

@Juneezee Looks like there's an issue with Windows here, I think you just need to add a defer o.Close() line 58 of ipc/cmd/arrow-stream-to-file/main_test.go can you give that a try?

I'm guessing it's not "closing" the file opened with ioutil.TempFile and so it's still considered to be "using" the file which is why os.RemoveAll errors.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
@Juneezee Juneezee requested a review from zeroshade August 8, 2022 15:58
@zeroshade zeroshade merged commit b1d36c0 into apache:master Aug 8, 2022
@zeroshade
Copy link
Member

Thanks @Juneezee!

@ursabot
Copy link

ursabot commented Aug 8, 2022

Benchmark runs are scheduled for baseline = c9ec543 and contender = b1d36c0. b1d36c0 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Failed ⬇️0.17% ⬆️0.03%] test-mac-arm
[Finished ⬇️0.0% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.14% ⬆️0.04%] ursa-thinkcentre-m75q
Buildkite builds:
[Finished] b1d36c02 ec2-t3-xlarge-us-east-2
[Failed] b1d36c02 test-mac-arm
[Finished] b1d36c02 ursa-i9-9960x
[Finished] b1d36c02 ursa-thinkcentre-m75q
[Finished] c9ec5438 ec2-t3-xlarge-us-east-2
[Finished] c9ec5438 test-mac-arm
[Finished] c9ec5438 ursa-i9-9960x
[Finished] c9ec5438 ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

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

3 participants