Skip to content

Commit

Permalink
Back off between attempts to start the tests (#15106)
Browse files Browse the repository at this point in the history
Looking through this test, I seriously don't understand how this doesn't
work. I mean, I don't really get how it _does_ work, but at this point
in the tests, we've actually established that both `Nihilist.exe` _and_
openconsole are running. From my read, there's no reason these should be
failing at this point.

We previously added a "retry 5 times" bit to this test, in #8534. That
did work back then. So uh, just do that... again?
  • Loading branch information
zadjii-msft authored Apr 13, 2023
1 parent f671f06 commit 72d0566
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/host/ft_host/InitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ MODULE_SETUP(ModuleSetup)
// to the one that belongs to the CMD.exe in the new OpenConsole.exe window.
VERIFY_WIN32_BOOL_SUCCEEDED_RETURN(FreeConsole());

// Wait a moment for the driver to be ready after freeing to attach.
VERIFY_WIN32_BOOL_SUCCEEDED_RETURN(AttachConsole(dwFindPid));

auto tries = 0;
while (tries < 5)
int tries = 0;
DWORD delay;
// This will wait for up to 32s in total (from 10ms to 163840ms)
for (delay = 10; delay < 30000u; delay *= 2)
{
tries++;
Log::Comment(NoThrowString().Format(L"Attempt #%d to confirm we've attached", tries));
Expand All @@ -267,17 +268,20 @@ MODULE_SETUP(ModuleSetup)
auto succeeded = GetConsoleScreenBufferInfoEx(hOut, &csbiexBefore);
if (!succeeded)
{
auto gle = GetLastError();
const auto gle = GetLastError();
VERIFY_ARE_EQUAL(6u, gle, L"If we fail to set up the console, GetLastError should return 6 here.");
Sleep(1000);

// Sleep with a backoff, to give us longer to try next time.
WaitForSingleObject(GetCurrentThread(), delay);
}
else
{
Log::Comment(NoThrowString().Format(L"Succeeded on try #%d", tries));
break;
}
};

VERIFY_IS_LESS_THAN(tries, 5, L"Make sure we set up the new console in time");
VERIFY_IS_LESS_THAN(delay, 30000u, L"Make sure we set up the new console in time");

return true;
}
Expand Down

0 comments on commit 72d0566

Please sign in to comment.