Skip to content

Commit 527742b

Browse files
authored
wait for the Agent MSI product registration and InstallPath registry … (#53656)
…value to be restored after rollback before asserting the installer state ### What does this PR do? This PR addresses a race condition in `test/new-e2e/tests/installer/windows/TestExtensionPersistence` by waiting for the Agent MSI product registration and InstallPath registry value to be restored after rollback before asserting the installer state. ### Motivation [WINA-2821](https://datadoghq.atlassian.net/browse/WINA-2821) ### Describe how you validated your changes Validation with stress test. ### Additional Notes [WINA-2821]: https://datadoghq.atlassian.net/browse/WINA-2821?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: hongshi.guo <hongshi.guo@datadoghq.com>
1 parent af0ce2f commit 527742b

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

test/new-e2e/tests/installer/windows/agent_upgrade_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package installer
99

1010
import (
1111
"context"
12+
"errors"
1213
"fmt"
1314
"os"
1415
"strings"
@@ -903,11 +904,38 @@ func (s *testAgentUpgradeSuite) waitForExperimentMSIRollback() {
903904
// so we can wait for the stable version to be placed on disk once again via MSI rollback
904905
err = s.waitForInstallerVersion(s.StableAgentVersion().Version())
905906
s.Require().NoError(err)
907+
// The installer binary can be present before Windows Installer has finished
908+
// restoring product registration and Agent registry values.
909+
err = s.waitForAgentMSIInstalledState()
910+
s.Require().NoError(err)
906911
// and wait again to ensure the stable service is running
907912
err = s.WaitForInstallerService("Running")
908913
s.Require().NoError(err)
909914
}
910915

916+
func (s *testAgentUpgradeSuite) waitForAgentMSIInstalledState() error {
917+
_, err := backoff.Retry(context.Background(), func() (any, error) {
918+
productCode, err := windowsagent.GetDatadogAgentProductCode(s.Env().RemoteHost)
919+
if err != nil {
920+
return nil, fmt.Errorf("Datadog Agent product is not registered yet: %w", err)
921+
}
922+
if strings.TrimSpace(productCode) == "" {
923+
return nil, errors.New("Datadog Agent product code is empty")
924+
}
925+
926+
installPath, err := windowsagent.GetInstallPathFromRegistry(s.Env().RemoteHost)
927+
if err != nil {
928+
return nil, fmt.Errorf("Datadog Agent InstallPath is not restored yet: %w", err)
929+
}
930+
if strings.TrimSpace(installPath) == "" {
931+
return nil, errors.New("Datadog Agent InstallPath is empty")
932+
}
933+
934+
return nil, nil
935+
}, backoff.WithBackOff(backoff.NewConstantBackOff(5*time.Second)), backoff.WithMaxTries(100))
936+
return err
937+
}
938+
911939
// setExperimentMSIArgs stores a list of MSI options for the installer to provide to the MSI when starting an experiment.
912940
func (s *testAgentUpgradeSuite) setExperimentMSIArgs(args []string) {
913941
err := windowscommon.SetRegistryMultiString(s.Env().RemoteHost, `HKLM:SOFTWARE\Datadog\Datadog Agent`, "StartExperimentMSIArgs", args)

test/new-e2e/tests/installer/windows/persisting_extensions_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ func (s *testExtensionsSuite) TestExtensionRestoredOnMSIRollback() {
255255
err = s.waitForInstallerVersion(s.StableAgentVersion().Version())
256256
s.Require().NoError(err)
257257

258+
err = s.waitForAgentMSIInstalledState()
259+
s.Require().NoError(err)
260+
258261
s.Require().Host(s.Env().RemoteHost).
259262
HasDatadogInstaller().
260263
WithVersionMatchPredicate(func(version string) {

0 commit comments

Comments
 (0)