pmasson

How to terminate unit tests run correctly

Discussion created by pmasson on Oct 16, 2020
Latest reply on Oct 23, 2020 by pmasson

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));

    }
}

Outcomes