From 0fd81a83e8a0f0c799e006b0be03205533ca2750 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 2 Sep 2020 19:57:54 +0800 Subject: [PATCH] executor: fix file exists errors in tests for `select into outfile` (#19717) Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com> --- executor/select_into_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/executor/select_into_test.go b/executor/select_into_test.go index cf30cfa89067d..33346d4330104 100644 --- a/executor/select_into_test.go +++ b/executor/select_into_test.go @@ -35,8 +35,12 @@ func cmpAndRm(expected, outfile string, c *C) { c.Assert(os.Remove(outfile), IsNil) } +func randomSelectFilePath(testName string) string { + return filepath.Join(os.TempDir(), fmt.Sprintf("select-into-%v-%v.data", testName, time.Now().Nanosecond())) +} + func (s *testSuite1) TestSelectIntoFileExists(c *C) { - outfile := filepath.Join(os.TempDir(), fmt.Sprintf("TestSelectIntoFileExists-%v.data", time.Now().Nanosecond())) + outfile := randomSelectFilePath("TestSelectIntoFileExists") defer func() { c.Assert(os.Remove(outfile), IsNil) }() @@ -51,8 +55,7 @@ func (s *testSuite1) TestSelectIntoFileExists(c *C) { } func (s *testSuite1) TestSelectIntoOutfileTypes(c *C) { - tmpDir := os.TempDir() - outfile := filepath.Join(tmpDir, "select-into-outfile.data") + outfile := randomSelectFilePath("TestSelectIntoOutfileTypes") tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -86,8 +89,7 @@ func (s *testSuite1) TestSelectIntoOutfileTypes(c *C) { } func (s *testSuite1) TestSelectIntoOutfileFromTable(c *C) { - tmpDir := os.TempDir() - outfile := filepath.Join(tmpDir, "TestSelectIntoOutfileFromTable.data") + outfile := randomSelectFilePath("TestSelectIntoOutfileFromTable") tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -128,8 +130,7 @@ func (s *testSuite1) TestSelectIntoOutfileFromTable(c *C) { } func (s *testSuite1) TestSelectIntoOutfileConstant(c *C) { - tmpDir := os.TempDir() - outfile := filepath.Join(tmpDir, "TestSelectIntoOutfileConstant.data") + outfile := randomSelectFilePath("TestSelectIntoOutfileConstant") tk := testkit.NewTestKit(c, s.store) // On windows the outfile name looks like "C:\Users\genius\AppData\Local\Temp\select-into-outfile.data", // fmt.Sprintf("%q") is used otherwise the string become