Provide an option to clean temp directory after running Go tests
Search before asking
- [X] I had searched in the issues and found no similar issues.
Motivation
Currently, after running the Go test, in the workspace, temp directories for each case will be created, which include the db logs.
λ ~/workspace/incubator-kvrocks/tests/gocase/workspace/ issue-816 du -h --max-depth=1
75M ./TestList-1662965128040-1301705625
1.7G ./TestZipList-1662965129047-2609311019
1.8G .
λ ~/workspace/incubator-kvrocks/tests/gocase/workspace/TestZipList-1662965129047-2609311019/db/archive/ issue-816 ll -h
total 1.1G
-rw-r--r-- 1 suicca suicca 62M Sep 12 14:45 000012.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000015.log
-rw-r--r-- 1 suicca suicca 60M Sep 12 14:45 000016.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000018.log
-rw-r--r-- 1 suicca suicca 60M Sep 12 14:45 000020.log
-rw-r--r-- 1 suicca suicca 60M Sep 12 14:45 000022.log
-rw-r--r-- 1 suicca suicca 60M Sep 12 14:45 000023.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000025.log
-rw-r--r-- 1 suicca suicca 38M Sep 12 14:45 000026.log
-rw-r--r-- 1 suicca suicca 22M Sep 12 14:45 000028.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000031.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000032.log
-rw-r--r-- 1 suicca suicca 60M Sep 12 14:45 000034.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000035.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000037.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000038.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000040.log
-rw-r--r-- 1 suicca suicca 59M Sep 12 14:45 000041.log
-rw-r--r-- 1 suicca suicca 22M Sep 12 14:45 000043.log
The problem is that the db folders occupy too much disk space. My disk just ran out of space after running test many times : (
Solution
Maybe we could pass a custom flag -clean-temp to go test command, indicating whether to clean the temp directory when the tests finish. And this should be disabled by default.
go test -v ./... -clean-temp
In func StartServer of tests/gocase/util/server.go, we read this flag and decide whether to perform cleaning in func (s *KvrocksServer) Close(). To do cleaning, we just need to simply delete the temp directory by its name, which is generated in StartServer.
It is also reasonable to do cleaning only when all the tests pass. But I think when we are developing test cases, there will still be bunch of test failure; And this would be more complicated since it requires to obtaining the test result. So, I prefer to let this flag to control whether the temp dir will be cleaned.
For VSCode users, extra flags could be configured via Go: Generate Tests Flags.
Are you willing to submit a PR?
- [X] I'm willing to submit a PR!
It sounds good to me. cc @tisonkun
+1 I have a similar idea. Glad to see someone pick it up. ~~Wire to the x.py script may spend some time to improve the usability. I notice that current we pass rest at the end and it conflicts how go test processes args.~~
+1 I have a similar idea. Glad to see someone pick it up. Wire to the
x.pyscript may spend some time to improve the usability. I notice that current we passrestat the end and it conflicts howgo testprocesses args.
@tisonkun Maybe it is because <build-dir> is not specified? If you want to pass rest, <build-dir> will become a required option, e.g.
./x.py test go <build-dir> --some-args
to
go test ./... --some-args
# usage: go test [build/test flags] [packages] [build/test flags & test binary flags]
@PragmaTwice you're right!
This patch can work, but we may think a bit more on the CLI arguments part - how to pass the option.
diff --git a/tests/gocase/util/server.go b/tests/gocase/util/server.go
index d0ab1b7..3c80ec8 100644
--- a/tests/gocase/util/server.go
+++ b/tests/gocase/util/server.go
@@ -113,6 +113,7 @@ func StartServer(t testing.TB, configs map[string]string) *KvrocksServer {
clean: func() {
require.NoError(t, stdout.Close())
require.NoError(t, stderr.Close())
+ require.NoError(t, os.RemoveAll(dir))
},
}
}