Skip to content

fix(provisioner/terraform/cleanup): use mtime instead of atime #10892

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

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Nov 27, 2023

  • Updates existing unit test to use a real filesystem as Afero's in-memory FS doesn't support atimes at all
  • Updates plugin staleness check to check mtime instead of atime, as atime has been shown to be unreliable

@johnstcn johnstcn self-assigned this Nov 27, 2023
@johnstcn johnstcn changed the title fix(provisioner): cleanup: use mtime instead of atime fix(provisioner/terraform/cleanup): use mtime instead of atime Nov 27, 2023
@johnstcn johnstcn marked this pull request as ready for review November 27, 2023 14:23
@johnstcn johnstcn requested review from mtojek and mafredri November 27, 2023 14:23
require.NoError(t, err, "can't stat parent")
if parentInfo.ModTime().After(mtime) {
require.NoError(t, fs.Chtimes(parent, atime, mtime), "can't set mtime of parent to match child")
}
Copy link
Member Author

Choose a reason for hiding this comment

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

review: bit hacky but we want this to look as close to reality as possible

Copy link
Member

Choose a reason for hiding this comment

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

just double-check: this should work consistency for different OSes? no risk of flakiness?

Copy link
Member Author

Choose a reason for hiding this comment

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

We use a different tempdir for each test and perform the file operations in serial, so it should probably be OK.

Comment on lines 117 to 118
addPluginFolder(t, fs, coderPluginPath, "new_folder", now, now.Add(-43*24*time.Hour))
addPluginFile(t, fs, coderPluginPath, filepath.Join("new_folder", "foobar.tf"), now, now.Add(-4*time.Hour)) // touched
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the intent of this test was to ensure that a plugin didn't get marked as stale if a file within its folder got touched, but the test was touching a directory. Updated to match.

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

👍

fs := afero.NewMemMapFs()
now := time.Date(2023, time.June, 3, 4, 5, 6, 0, time.UTC)
prepare := func() (afero.Fs, slog.Logger) {
// afero.MemMapFs does not modify atimes, so use a real FS instead.
Copy link
Member

Choose a reason for hiding this comment

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

:(

require.NoError(t, err, "can't stat parent")
if parentInfo.ModTime().After(mtime) {
require.NoError(t, fs.Chtimes(parent, atime, mtime), "can't set mtime of parent to match child")
}
Copy link
Member

Choose a reason for hiding this comment

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

just double-check: this should work consistency for different OSes? no risk of flakiness?

@@ -7,7 +7,6 @@ import (
"strings"
"time"

"github.com/djherbis/times"
Copy link
Member

Choose a reason for hiding this comment

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

nit: tidy go.mod or not yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, still referenced in provisionersdk Sessions cleanup. I'll do a separate PR for this.

@johnstcn johnstcn merged commit 0babc3c into main Nov 27, 2023
@johnstcn johnstcn deleted the cj/provisioner-cleanup-mtime branch November 27, 2023 15:19
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants