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

When a TIMED OUT occur we do not clean the go-build* folder in /tmp #182

Closed
alessio-perugini opened this issue Oct 2, 2022 · 7 comments · Fixed by #183
Closed

When a TIMED OUT occur we do not clean the go-build* folder in /tmp #182

alessio-perugini opened this issue Oct 2, 2022 · 7 comments · Fixed by #183
Assignees
Labels
c/enhancement Category: An issue or PR related to sn enhancement
Milestone

Comments

@alessio-perugini
Copy link
Contributor

When we call the go test it first builds all the files needed to run the tests. The build artifacts are created under /tmp dir by default and have a name like go-build19625282.

Every time we kill the execution of go test it does not clean the build directory created under the /tmp dir. This means that every time we have a mutation that goes on TIMED_OUT we do not clear the relative build dirs.

Step I did to reproduce:

  1. rm -rf /tmp/go-build*
  2. gremlin unleash | grep "TIMED OUT" | wc -l
  3. ls /tmp | grep go-build | wc -l

Solution

Set the GOTMPDIR env var that will be used by go test to store all the build dirs of gremlins. Clean up that folder before quitting gremlins.

@k3rn31
Copy link
Member

k3rn31 commented Oct 3, 2022

This is almost the same as #177, and both the solution proposed are analogous. Maybe it is worth to implement them together. What do you think? Is GOTMPDIR used only by tests?

@k3rn31 k3rn31 added the c/enhancement Category: An issue or PR related to sn enhancement label Oct 3, 2022
@alessio-perugini
Copy link
Contributor Author

@k3rn31 Actually yes we can implement both in the same PR.
From go doc:

By default, the go tool creates its temporary files and directories in the system temporary directory (for example, $TMPDIR on Unix). If the new environment variable $GOTMPDIR is set, the go tool will create its temporary files and directories in that directory instead.

if you only export the GOCACHE go test still creates go-build dirs in the /tmp folder. So changing the GOTMPDIR will move those folders in whatever dir we choose.

I did a quick test from the terminal:
Using GOCACHE

export GOCACHE=/tmp/gremlins 
./dist/bin/gremlins unleash .

When we have a timed_out we still have go-build folder in /tmp.

Using GOTMPDIR

export GOTMPDIR=/tmp/gremlins
./dist/bin/gremlins unleash .

If we go under /tmp/gremlins we can find the go-build dirs there.

@alessio-perugini
Copy link
Contributor Author

@k3rn31 You can find my idea here: https://github.com/alessio-perugini/gremlins/pull/3/files
But I'm stuck because it seems to not work. Every mutation gets killed and I suspect we don't even build and run them because the total time is 387ms 🤔

@k3rn31
Copy link
Member

k3rn31 commented Oct 3, 2022

@alessio-perugini I did, more or less, the same experiment yesterday with the same result, everything KILLED... I don't know why 😄
I was trying to understand how to implement #177.

@alessio-perugini
Copy link
Contributor Author

@k3rn31 using os.Setenv("GOTMPDIR", filepath.Dir(rootDir)) seems to work fine. 🤯

func (m *mutantExecutor) Start(w *workerpool.Worker) {
	defer m.wg.Done()
	workerName := fmt.Sprintf("%s-%d", w.Name, w.ID)
	rootDir, err := m.wdDealer.Get(workerName)
	if err != nil {
		panic("error, this is temporary")
	}

	os.Setenv("GOTMPDIR", filepath.Dir(rootDir))
     ...

@k3rn31
Copy link
Member

k3rn31 commented Oct 3, 2022

I believe you have to execute

cmd.Env = os.Environ()

before setting the GOTMPDIR variable, otherwise you will lose the current env (only GOTMPDIR will be present).

cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, m.goTmpDirEnv)

@k3rn31 k3rn31 added this to the v0.5.0 milestone Oct 3, 2022
@alessio-perugini
Copy link
Contributor Author

@k3rn31 How I couldn't think about that! Your suggestion is working flawlessly 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/enhancement Category: An issue or PR related to sn enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants