From 50b68c168c3ea3bee751cbcde542c285b1a01f11 Mon Sep 17 00:00:00 2001
From: Laura Brehm <laurabrehm@hey.com>
Date: Thu, 1 Aug 2024 12:34:33 +0100
Subject: [PATCH] tests: fix flaky `TestLoginDevice` test

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
---
 cli/internal/oauth/manager/manager_test.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/cli/internal/oauth/manager/manager_test.go b/cli/internal/oauth/manager/manager_test.go
index f49f7c54daec..0aefb8136e4d 100644
--- a/cli/internal/oauth/manager/manager_test.go
+++ b/cli/internal/oauth/manager/manager_test.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"os"
 	"testing"
+	"time"
 
 	"github.com/docker/cli/cli/internal/oauth/api"
 	"github.com/docker/cli/cli/oauth"
@@ -122,6 +123,8 @@ func TestLoginDevice(t *testing.T) {
 			}, nil
 		}
 		waitForDeviceToken := func(state api.State) (api.TokenResponse, error) {
+			// make sure that the context is cancelled before this returns
+			time.Sleep(500 * time.Millisecond)
 			return api.TokenResponse{
 				AccessToken:  validToken,
 				RefreshToken: "refresh-token",