C
C#2y ago
Hypaxba_

❔ Testhost process crash when throwing an Exception and reading the Console.

Hello, I'm encountering a problem using Xunit. I'm using Xunit to test untrusted student code. We implemented a Timeout mechanic that throws an exception if the student code runs for too long. This works well on tests that just checks for return values. However, when I'm testing for Console Output in this way, I encounter a System.IO.EndOfStreamException when this Timeout Exception is thrown. The code that test for this looks like this:
StringWriter swref = new StringWriter();
Console.SetOut(swref);
//Student code that timeout
string res = swref.ToString()
// Assert call
StringWriter swref = new StringWriter();
Console.SetOut(swref);
//Student code that timeout
string res = swref.ToString()
// Assert call
I'm pretty sure it comes from this comes from the Timeout exception, as the logs I get with --diag shows that this occurs before the TestHost Process crashes. I tried catching the exception but the output is still the same. The thing that I don't understand as well is that it runs fine when running the tests locally, but we use docker containers that run with 1GB ram and 1 cpu core and no access to the internet to run student code, and it is where I encounter this issue. Thanks for your help The logs I get with --diag is as follows (cut down to the relevant part):
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.