-
Notifications
You must be signed in to change notification settings - Fork 19
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
Use GOTMPDIR env to clean all the go-build folders #183
Use GOTMPDIR env to clean all the go-build folders #183
Conversation
51c9dcc
to
0a7e609
Compare
Codecov Report
@@ Coverage Diff @@
## main #183 +/- ##
==========================================
+ Coverage 88.23% 88.27% +0.03%
==========================================
Files 18 18
Lines 1284 1288 +4
==========================================
+ Hits 1133 1137 +4
Misses 126 126
Partials 25 25
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Thanks for the PR. I'd do the refactoring, I don't think we need it in the mutator. Do you think this also closes #177? |
|
No, I meant the second approach where the Dealer gives the root. Seems cleaner, so we set it just once, but it is explicit that the temp dir is modified when we call the command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a test to the dealer for WorkDir to be consistent.
e86fd77
to
691a422
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a couple of comments. Please, check if they make sense to you, otherwise we can proceed with the merge.
@@ -199,6 +200,8 @@ func (m *mutantExecutor) runTests(pkg string) mutator.Status { | |||
|
|||
cmd := m.execContext(ctx, "go", m.getTestArgs(pkg)...) | |||
cmd.Dir = m.mutant.Workdir() | |||
cmd.Env = append(cmd.Env, os.Environ()...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be better to do cmd.Env = os.Environ
. Not sure, but I think we can spare an array allocation.
At the beginning Env should be nil, in the first append, it allocates an array with the length of Environ. Then, in the second array it reallocates for the added element, isn't it?
If we assign Environ directly, we are sure at most it reallocates in the only append we have. I'm not certain my reasoning is correct though 😄. What do you thin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason I did that is to not break test in: TestMutatorTestExecution
. In the executor_test.go:557
we set the GO_TEST_PROCESS=1
if we do not append we will override that breaking 2 tests.
About the allocation, since the os.Environ should be more or less the same every time we call it (at least the env vars we need). We might want to refactor where we assign that line.
We can create our custom execContext func that pre-allocates the env vars, so we will do the allocation and the sys call only once, and not every time we call the runTests
func:
func NewExecutorDealer(mod gomodule.GoModule, wdd workdir.Dealer, elapsed time.Duration, opts ...ExecutorDealerOption) *MutantExecutorDealer {
...
jd := MutantExecutorDealer{
...
execContext: commandWithEnvs,
}
...
}
func commandWithEnvs(ctx context.Context, name string, arg ...string) *exec.Cmd {
cmd := exec.CommandContext(ctx, name, arg...)
cmd.Env = os.Environ()
return cmd
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if the env is set at every mutator run (potentially a lot of times) I was concerned, but maybe what we gain not reallocating is marginal and doesn't justify this refactoring, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should perform some benchmarks. I think it won't be the most expensive operation we're doing so we should be fine for now running that code for every mutator.
internal/engine/executor_test.go
Outdated
@@ -461,6 +461,53 @@ func TestMutatorRunInTheCorrectFolder(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestMutatorRunWithCorrectEnvs(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this test can be integrated in the TestMutatorTestExecution
, they are almost identical.
1795435
to
e90be61
Compare
Proposed changes
Closes #182.
Types of changes
Checklist
make all
)Further comments
The proposed PR is an idea to overcome the issue of not cleaning build folders when going into time out.
Writing the test it felt a bit awkward the way I got the root dir of our
wdDealer
. I think in writing this line:I'm leaking implementation logic in our test.
So I was thinking of another way to get the same result in a cleaner way. We might add a new func in the
Dealer interface
that returns the root working directory.Introduction the
WorkDir()
getter we can also refactor the implementation in just this 2 lines:WDYT? Should I do the proposed refactoring? Do you suggest other improvements/solutions?