Skip to content

Commit

Permalink
Re-enable TestFQDN (#3911)
Browse files Browse the repository at this point in the history
* Re-enable TestFQDN

* Add debugging statement

* Add convenience method

* Remove debugging statement

* Create new context as old one is already canceled
  • Loading branch information
ycombinator authored Dec 14, 2023
1 parent 76ce7f1 commit b5ff06b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/testing/tools/testcontext/testcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ func WithDeadline(
ctx, cancel := context.WithDeadline(parent, deadline)
return ctx, cancel
}

// WithTimeout returns a context with a deadline calculated from the provided
// timeout duration. It is the equivalent of calling WithDeadline with the
// deadline specified as time.Now() + timeout.
func WithTimeout(
t *testing.T,
parentCtx context.Context,
timeout time.Duration,
) (context.Context, context.CancelFunc) {
return WithDeadline(t, parentCtx, time.Now().Add(timeout))
}
4 changes: 3 additions & 1 deletion testing/integration/fqdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestFQDN(t *testing.T) {
Local: false,
Sudo: true,
})
t.Skip("Flaky test, see https://github.com/elastic/elastic-agent/issues/3154")

agentFixture, err := define.NewFixture(t, define.Version())
require.NoError(t, err)
Expand Down Expand Up @@ -96,6 +95,9 @@ func TestFQDN(t *testing.T) {
assert.NoError(t, fleettools.UnEnrollAgent(info.KibanaClient, policy.ID))

t.Log("Restoring hostname...")
ctx, cancel := testcontext.WithTimeout(t, context.Background(), 1*time.Minute)
defer cancel()

err := setHostname(ctx, origHostname, t.Log)
require.NoError(t, err)

Expand Down

0 comments on commit b5ff06b

Please sign in to comment.