How to terminate unit tests run correctly

1073
2
10-16-2020 09:30 AM
PierreMasson
Occasional Contributor

Hi,

I have a bunch of unit tests (MSTest) using ArcGis Pro SDK. 

All my tests run well except that when the test run is done, the testhost.exe process stay alive. That prevents the unit test task in TFS (Azure) to complete. It's stay there for 45 minutes before TFS stopping it. If I go on the server and kill the testhost.exe process, the MSTest task terminate correctly.

I think it's related to QueuedTasks used to run the test. I have other tests that don't use queuedTask and the testhost.exe process shuts down after test completion.

I've tried everything and I can reproduce the behavior easily with this simple sample.

Can you help please? What is the correct way to do it?

[TestClass]
public class Test_entity
{
    [ClassInitialize]
    public static void ClassInitialize(TestContext context)
    {
        Host.Initialize();
    }


    PipeService _entityService;
    public override IEntityService<Pipe> entityService
    {
        get
        {
            if(_entityService == null)
            {
                _entityService = new PipeService();
            }
            return _entityService;
        }
    }


    public TestContext TestContext { get; set; }

    

    public IEntityService<Pipe> entityService { get; }

    

    [TestMethod]
    [DeploymentItem("mockData\\GDB")]
    [DeploymentItem("unitsData", "unitsData")]
    [TestCategory("Entities")]
    [STAThread]
    public void TestGetByObjectId()
    {

        Pipe entity = null;
        Task t = QueuedTask.Run(() =>
        {
            entity = entityService.getByObjectId(1);

        });

        t.Wait();
        t.Dispose();
        Assert.IsTrue(entity != null));

    }
}

0 Kudos
2 Replies
PierreMasson
Occasional Contributor

Unit Testing code that runs QueuedTasks seems to leave things open that makes testhost.exe process waiting on something. How can I clean all threads/task at the end of my tests?

0 Kudos
PierreMasson
Occasional Contributor

ArcGis Pro SDK is base on MVVM. That means you can test your business presentation. So view models will have QueueTasks in it. Anybody has been able to have unit tests running coorectly on continuous integration?? 

0 Kudos