Repository: kopia/kopia
Pull request #3625 (2024-02-06 01:04:23)

fix(snapshots): Fixup for #3624.  Shadow copy seems to extend time for snapshots.
PR https://github.com/kopia/kopia/pull/3543 seems to put IO resource pressure on the system.  Enough to cause `TestServerScheduling` to fail due to snapshot latencies - which, in turn, causes Windows tests to fail as a flake.

This PR embodies the fix suggested by @jkowalski.

This fix also fixes the SIGFAULTS caused by use of the `-race` flag, which points to a possible problem in dependent library.

Shrekster: @aaron-kasten , how about keeping the test enabled with a simple change of enabling the VSS policy just for the test and keeping it disabled by default otherwise as you already did:

```diff
 func TestSetOSSnapshotPolicy(t *testing.T) {
-       t.Skip("See ticket https://github.com/kopia/kopia/issues/3624")
        e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
-
        defer e.RunAndExpectSuccess(t, "repo", "disconnect")

        e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)

        lines := e.RunAndExpectSuccess(t, "policy", "show", "--global")
        lines = compressSpaces(lines)
+       require.Contains(t, lines, " Volume Shadow Copy: never (defined for this target)")
+
+       e.RunAndExpectSuccess(t, "policy", "set", "--global", "--enable-volume-shadow-copy=when-available")
+
+       lines = e.RunAndExpectSuccess(t, "policy", "show", "--global")
+       lines = compressSpaces(lines)
        require.Contains(t, lines, " Volume Shadow Copy: when-available (defined for this target)")

        // make some directory we'll be setting policy on
```
aaron-kasten: > @aaron-kasten , how about keeping the test enabled with a simple change of enabling the VSS policy just for the test and keeping it disabled by default otherwise as you already did:
> 
> ```diff
> diff --git a/cli/command_policy_set_os_snapshot_test.go b/cli/command_policy_set_os_snapshot_test.go
> index 6165a09d..ac8e86f7 100644
> --- a/cli/command_policy_set_os_snapshot_test.go
> +++ b/cli/command_policy_set_os_snapshot_test.go
> @@ -10,15 +10,19 @@
>  )
> 
>  func TestSetOSSnapshotPolicy(t *testing.T) {
> -       t.Skip("See ticket https://github.com/kopia/kopia/issues/3624")
>         e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
> -
>         defer e.RunAndExpectSuccess(t, "repo", "disconnect")
> 
>         e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
> 
>         lines := e.RunAndExpectSuccess(t, "policy", "show", "--global")
>         lines = compressSpaces(lines)
> +       require.Contains(t, lines, " Volume Shadow Copy: never (defined for this target)")
> +
> +       e.RunAndExpectSuccess(t, "policy", "set", "--global", "--enable-volume-shadow-copy=when-available")
> +
> +       lines = e.RunAndExpectSuccess(t, "policy", "show", "--global")
> +       lines = compressSpaces(lines)
>         require.Contains(t, lines, " Volume Shadow Copy: when-available (defined for this target)")
> 
>         // make some directory we'll be setting policy on
> ```

@Shrekster that looks great.  As long as this PR's test passes and other PRs are not blocked.  I'm not so versed in VSS as to be able to make a judgement on  the quality of the fix beyond that.

Patch:
diff --git a/snapshot/policy/policy_tree.go b/snapshot/policy/policy_tree.go
index ee99a4a0..33bd9731 100644
--- a/snapshot/policy/policy_tree.go
+++ b/snapshot/policy/policy_tree.go
@@ -55,7 +55,7 @@
 
 	defaultOSSnapshotPolicy = OSSnapshotPolicy{
 		VolumeShadowCopy: VolumeShadowCopyPolicy{
-			Enable: NewOSSnapshotMode(OSSnapshotWhenAvailable),
+			Enable: NewOSSnapshotMode(OSSnapshotNever),
 		},
 	}
 


Test patch:
diff --git a/cli/command_policy_set_os_snapshot_test.go b/cli/command_policy_set_os_snapshot_test.go
index 5aea57bb..a91083d0 100644
--- a/cli/command_policy_set_os_snapshot_test.go
+++ b/cli/command_policy_set_os_snapshot_test.go
@@ -17,6 +17,13 @@ func TestSetOSSnapshotPolicy(t *testing.T) {
 
 	lines := e.RunAndExpectSuccess(t, "policy", "show", "--global")
 	lines = compressSpaces(lines)
+	require.Contains(t, lines, " Volume Shadow Copy: never (defined for this target)")
+
+	e.RunAndExpectSuccess(t, "policy", "set", "--global", "--enable-volume-shadow-copy=when-available")
+
+	lines = e.RunAndExpectSuccess(t, "policy", "show", "--global")
+	lines = compressSpaces(lines)
+
 	require.Contains(t, lines, " Volume Shadow Copy: when-available (defined for this target)")
 
 	// make some directory we'll be setting policy on