Flush input queue before running test. #1137 (#1139)

Flushes the input queue on RawReadUnpacksCoalescedInputRecords test to ensure that other tests cannot cause failure by leaving extraneous input records behind after they run.

This only failed in the core operating system gate tests. This is because those tests run a subset of the complete test suite (subtracting the ones that do not make sense in a core environment). Apparently one of the tests that was skipped that normally runs prior to the UnpacksCoalesced test ensured that the input queue was clean enough for this test to succeed. But in the core environment, the test that ran prior left stuff behind.

To resolve this, I'm making the Coalesced test more resilient by cleaning out the queue prior to performing its operations.

(Also, bonus, I'm fixing the typo in the name Coalesced.)

This is less complicated/expensive than tracking down the tests that are leaving garbage behind, should prevent issues in the future related to ordering (since the tests run alphabetically, by default), and isn't as expensive as running the test in isolation (with its own conhost stood up for just the one test.)

Validated by running te.exe Microsoft.Console.Host.FeatureTests.dll /name:*InputTests* against a core operating system variant. Prior to change, this test failed. After the change, this test succeeded.

This will be automatically double-checked by the gates run after check-in.
This commit is contained in:
Michael Niksa 2019-06-04 15:16:09 -07:00 committed by GitHub
parent 8a69be0cc7
commit 107ea3c2e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -55,7 +55,7 @@ class InputTests
TEST_METHOD(TestMouseHorizWheelReadConsoleNoMouseInput);
TEST_METHOD(TestMouseWheelReadConsoleInputQuickEdit);
TEST_METHOD(TestMouseHorizWheelReadConsoleInputQuickEdit);
TEST_METHOD(RawReadUnpacksCoalsescedInputRecords);
TEST_METHOD(RawReadUnpacksCoalescedInputRecords);
BEGIN_TEST_METHOD(TestVtInputGeneration)
TEST_METHOD_PROPERTY(L"IsolationLevel", L"Method")
@ -671,7 +671,7 @@ void InputTests::TestVtInputGeneration()
VERIFY_ARE_EQUAL(rgInputRecords[2].Event.KeyEvent.uChar.UnicodeChar, L'A');
}
void InputTests::RawReadUnpacksCoalsescedInputRecords()
void InputTests::RawReadUnpacksCoalescedInputRecords()
{
DWORD mode = 0;
HANDLE hIn = GetStdInputHandle();
@ -683,6 +683,10 @@ void InputTests::RawReadUnpacksCoalsescedInputRecords()
WI_ClearFlag(mode, ENABLE_LINE_INPUT);
SetConsoleMode(hIn, mode);
// flush input queue before attempting to add new events and check
// in case any are leftover from previous tests
VERIFY_WIN32_BOOL_SUCCEEDED(FlushConsoleInputBuffer(hIn));
INPUT_RECORD record;
record.EventType = KEY_EVENT;
record.Event.KeyEvent.bKeyDown = TRUE;