Skip to content

Commit 4f18bec

Browse files
committed
Remove DriverImplProxy because sometimes fails in parallel unit tests
1 parent ff69a2d commit 4f18bec

File tree

1 file changed

+24
-121
lines changed

1 file changed

+24
-121
lines changed

Tests/UnitTestsParallelizable/Drawing/Sixel/SixelSupportDetectorTests.cs

Lines changed: 24 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -159,74 +159,6 @@ public void Detect_SetsSupported_WhenIsVirtualTerminalIsTrueAndResponseContain4O
159159
driverMock.Verify (d => d.QueueAnsiRequest (It.IsAny<AnsiEscapeSequenceRequest> ()), Times.AtLeast (1));
160160
}
161161

162-
[Theory]
163-
[InlineData (true)]
164-
[InlineData (false)]
165-
public void Detect_SetsSupported_WhenIsVirtualTerminalIsTrueAndResponseContain4OrFalse_WithoutMock (bool isVirtualTerminal)
166-
{
167-
// Arrange
168-
var responseReceived = false;
169-
var output = new FakeOutput ();
170-
output.IsVirtualTerminal = isVirtualTerminal;
171-
172-
DriverImplProxy driver = new (
173-
new FakeInputProcessor (null!),
174-
new OutputBufferImpl (),
175-
output,
176-
new (new AnsiResponseParser ()),
177-
new SizeMonitorImpl (output)
178-
);
179-
180-
driver.Callback += req =>
181-
{
182-
if (req.Request == EscSeqUtils.CSI_SendDeviceAttributes.Request)
183-
{
184-
responseReceived = true;
185-
186-
if (isVirtualTerminal)
187-
{
188-
// Response does contain "4" (so DAR indicates has sixel)
189-
req.ResponseReceived.Invoke ("?1;4;0;7c");
190-
}
191-
else
192-
{
193-
// Response does NOT contain "4" (so DAR indicates no sixel)
194-
req.ResponseReceived.Invoke ("");
195-
}
196-
197-
return true;
198-
}
199-
200-
// Abandon all requests
201-
req.Abandoned?.Invoke ();
202-
203-
return false;
204-
};
205-
206-
var detector = new SixelSupportDetector (driver);
207-
SixelSupportResult? final = null;
208-
209-
// Act
210-
detector.Detect (r => final = r);
211-
212-
// Assert
213-
Assert.Equal (isVirtualTerminal, driver.IsVirtualTerminal);
214-
Assert.NotNull (final);
215-
216-
if (isVirtualTerminal)
217-
{
218-
Assert.True (final.IsSupported);
219-
Assert.False (final.SupportsTransparency);
220-
}
221-
else
222-
{
223-
// Not a real VT, so shouldn't be supported
224-
Assert.False (final.IsSupported);
225-
Assert.False (final.SupportsTransparency);
226-
}
227-
Assert.True (responseReceived);
228-
}
229-
230162
[Theory]
231163
[InlineData (true)]
232164
[InlineData (false)]
@@ -237,39 +169,40 @@ public void Detect_SetsSupported_WhenIsVirtualTerminalIsTrueOrFalse_With_Respons
237169
var output = new FakeOutput ();
238170
output.IsVirtualTerminal = isVirtualTerminal;
239171

240-
DriverImplProxy driver = new (
241-
new FakeInputProcessor (null!),
242-
new OutputBufferImpl (),
243-
output,
244-
new (new AnsiResponseParser ()),
245-
new SizeMonitorImpl (output)
246-
);
247-
248-
driver.Callback += req =>
249-
{
250-
if (req.Request == EscSeqUtils.CSI_SendDeviceAttributes.Request)
251-
{
252-
responseReceived = true;
172+
Mock<DriverImpl> driverMock = new (
173+
MockBehavior.Strict,
174+
new FakeInputProcessor (null!),
175+
new OutputBufferImpl (),
176+
output,
177+
new AnsiRequestScheduler (new AnsiResponseParser ()),
178+
new SizeMonitorImpl (output)
179+
);
253180

254-
// Respond to the SendDeviceAttributes request with a value that indicates support (contains "4")
255-
// Respond to the SendDeviceAttributes request with an empty value that indicates non-support
256-
req.ResponseReceived.Invoke (driver.IsVirtualTerminal ? "1;4;7c" : "");
257-
}
181+
driverMock.Setup (d => d.QueueAnsiRequest (It.IsAny<AnsiEscapeSequenceRequest> ()))
182+
.Callback<AnsiEscapeSequenceRequest> (req =>
183+
{
184+
if (req.Request == EscSeqUtils.CSI_SendDeviceAttributes.Request)
185+
{
186+
responseReceived = true;
258187

259-
// Abandon all requests
260-
req.Abandoned?.Invoke ();
188+
// Respond to the SendDeviceAttributes request with a value that indicates support (contains "4")
189+
// Respond to the SendDeviceAttributes request with an empty value that indicates non-support
190+
req.ResponseReceived.Invoke (driverMock.Object.IsVirtualTerminal ? "1;4;7c" : "");
191+
}
261192

262-
return true;
263-
};
193+
// Abandon all requests
194+
req.Abandoned?.Invoke ();
195+
})
196+
.Verifiable ();
264197

265-
var detector = new SixelSupportDetector (driver);
198+
var detector = new SixelSupportDetector (driverMock.Object);
266199
SixelSupportResult? final = null;
267200

268201
// Act
269202
detector.Detect (r => final = r);
270203

271204
// Assert
272-
Assert.Equal (isVirtualTerminal, driver.IsVirtualTerminal);
205+
Assert.Equal (isVirtualTerminal, driverMock.Object.IsVirtualTerminal);
273206
Assert.NotNull (final);
274207

275208
if (isVirtualTerminal)
@@ -287,33 +220,3 @@ public void Detect_SetsSupported_WhenIsVirtualTerminalIsTrueOrFalse_With_Respons
287220
Assert.True (responseReceived);
288221
}
289222
}
290-
291-
/// <inheritdoc />
292-
internal class DriverImplProxy : DriverImpl
293-
{
294-
/// <inheritdoc />
295-
public DriverImplProxy (IInputProcessor inputProcessor,
296-
IOutputBuffer outputBuffer,
297-
IOutput output,
298-
AnsiRequestScheduler ansiRequestScheduler,
299-
ISizeMonitor sizeMonitor) : base (inputProcessor, outputBuffer, output, ansiRequestScheduler, sizeMonitor)
300-
{ }
301-
302-
public Func<AnsiEscapeSequenceRequest, bool>? Callback { get; set; }
303-
304-
/// <inheritdoc />
305-
public override void QueueAnsiRequest (AnsiEscapeSequenceRequest request)
306-
{
307-
if (Callback is null)
308-
{
309-
throw new NullReferenceException ($"{nameof (Callback)} cannot be null.");
310-
}
311-
312-
if (!Callback (request))
313-
{
314-
base.QueueAnsiRequest (request);
315-
}
316-
317-
Callback = null;
318-
}
319-
}

0 commit comments

Comments
 (0)