Skip to content

Commit

Permalink
Add information to try to de-flake uninstall tests.
Browse files Browse the repository at this point in the history
Bug: b/283099145
Change-Id: Ib362f74938da2b64304d119b08cbd2cf2f8f8975
  • Loading branch information
bdhess committed May 17, 2023
1 parent 850f451 commit eeb5ada
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions kmscng/main/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,34 @@ const (
libraryFile = "C:\\Windows\\System32\\kmscng.dll"
registryKey = "HKLM\\System\\CurrentControlSet\\Control\\Cryptography\\Providers\\" +
providerName + "\\UM\\00010001"

fileRenamesKey = "HKLM\\System\\CurrentControlSet\\Control\\Session Manager\\FileRenameOperations"
pendingRenamesKey = "HKLM\\System\\CurrentControlSet\\Control\\Session Manager\\PendingFileRenameOperations"
)

func dllExists(t *testing.T, ctx context.Context) bool {
t.Helper()

// TODO(b/283099145): remove this logic and replace with a fix once we understand why this is flaky.
if out, err := exec.CommandContext(ctx, "reg", "query", fileRenamesKey).CombinedOutput(); err != nil {
t.Logf("reg query %s failed with error=%v", fileRenamesKey, err)
} else {
t.Logf("req query %s output:\n%s", fileRenamesKey, string(out))
}
if out, err := exec.CommandContext(ctx, "reg", "query", pendingRenamesKey).CombinedOutput(); err != nil {
t.Logf("reg query %s failed with error=%v", pendingRenamesKey, err)
} else {
t.Logf("req query %s output:\n%s", pendingRenamesKey, string(out))
}

if _, err := os.Stat(libraryFile); err == nil {
return true
} else if !errors.Is(err, fs.ErrNotExist) {
t.Fatalf("os.Stat(libraryFile) err=%v, want nil or fs.ErrNotExist", err)
}
return false
}

func regExists(t *testing.T, ctx context.Context) bool {
t.Helper()
out, err := exec.CommandContext(ctx, "reg", "query", registryKey).CombinedOutput()
Expand All @@ -55,17 +81,17 @@ func TestInstallUninstall(t *testing.T) {
if !regExists(t, ctx) {
t.Errorf("registry key %q is missing", registryKey)
}
if _, err := os.Stat(libraryFile); err != nil {
t.Errorf("os.Stat(libraryFile) err=%v, want nil", err)
if !dllExists(t, ctx) {
t.Errorf("library file %q is missing", libraryFile)
}

installtestlib.MustUninstall(t, ctx)

if regExists(t, ctx) {
t.Errorf("registry key %q unexpectedly exists", registryKey)
}
if _, err := os.Stat(libraryFile); !errors.Is(err, fs.ErrNotExist) {
t.Errorf("os.Stat(libraryFile) err=%v, want fs.ErrNotExist", err)
if dllExists(t, ctx) {
t.Errorf("library file %q unexpectedly exists", libraryFile)
}
}

Expand All @@ -81,8 +107,8 @@ func TestInstallUninstallInstall(t *testing.T) {
if !regExists(t, ctx) {
t.Errorf("registry key %q is missing", registryKey)
}
if _, err := os.Stat(libraryFile); err != nil {
t.Errorf("os.Stat(libraryFile) err=%v, want nil", err)
if !dllExists(t, ctx) {
t.Errorf("library file %q is missing", libraryFile)
}
}

Expand Down Expand Up @@ -115,7 +141,7 @@ func TestUninstallRemovesDllWhenRegistryEntryIsMissing(t *testing.T) {

installtestlib.MustUninstall(t, ctx)

if _, err := os.Stat(libraryFile); !errors.Is(err, fs.ErrNotExist) {
t.Errorf("os.Stat(libraryFile) err=%v, want fs.ErrNotExist", err)
if dllExists(t, ctx) {
t.Errorf("library file %q unexpectedly exists", libraryFile)
}
}

0 comments on commit eeb5ada

Please sign in to comment.