TaskCanceledException thrown at the end of NUnit test #10946
-
I am using all the latest packages and am trying to write my first Aspire test with NUnit. The test itself passes but if I debug it builder.Build().Run() throws a TaskCancelled exception. I don't get this exception if I debug the Aspire project normally so I'm assuming it must be something to do with my test setup. Unfortunately the exception gives me very little information to go on. Does anyone have ideas how I can get more detail about the problem? The exception:
The test:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @paulhunttech, |
Beta Was this translation helpful? Give feedback.
Hello @paulhunttech,
TaskCanceledException
happens becausebuilder.Build().Run()
blocks until shutdown, which doesn't work in a test runner context, the task gets canceled when the test ends.Since you're already using
DistributedApplicationTestingBuilder
, stick withBuildAsync()
+StartAsync()
(as in your test) instead ofRun()
. That’s the supported way to run Aspire apps in tests.