Mongo2Go: Can't run Mongo2Go on VSTS / Azure Devops

Currently, I’m working with Mongo2Go for unit test. But when I build my Project on VSTS and see it doesn’t work properly. You can check the following error

2018-08-09T09:06:03.9933372Z [xUnit.net 00:00:40.97]     xxxxxxx.BackEnd.Tests.Project.ProjectReadServiceTests.TestGetProjectDetailAsync [FAIL]
2018-08-09T09:06:04.0574498Z Failed   xxxxxxx.BackEnd.Tests.Project.ProjectReadServiceTests.TestGetProjectDetailAsync
2018-08-09T09:06:04.0574987Z Error Message:
2018-08-09T09:06:04.0575333Z  System.AggregateException : One or more errors occurred. (A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "2", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 2, EndPoint : "127.0.0.1:27019" }", EndPoint: "127.0.0.1:27019", State: "Disconnected", Type: "Unknown" }] }.)
2018-08-09T09:06:04.0575882Z ---- System.TimeoutException : A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "2", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 2, EndPoint : "127.0.0.1:27019" }", EndPoint: "127.0.0.1:27019", State: "Disconnected", Type: "Unknown" }] }.
2018-08-09T09:06:04.0576249Z Stack Trace:
2018-08-09T09:06:04.0576430Z    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
2018-08-09T09:06:04.0576638Z    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
2018-08-09T09:06:04.0576802Z    at System.Threading.Tasks.Task.Wait()
2018-08-09T09:06:04.0577004Z    at xxxxxxx.BackEnd.Tests.Project.ProjectReadServiceTests.TestGetProjectDetailAsync() in D:\a\1\s\Tests\xxxxxxx.BackEnd.Tests\Project\ProjectReadServiceTests.cs:line 116
2018-08-09T09:06:04.0577230Z ----- Inner Stack Trace -----
2018-08-09T09:06:04.0577420Z    at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
2018-08-09T09:06:04.0577636Z    at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
2018-08-09T09:06:04.0577823Z    at MongoDB.Driver.Core.Clusters.Cluster.<WaitForDescriptionChangedAsync>d__50.MoveNext()
2018-08-09T09:06:04.0578017Z --- End of stack trace from previous location where exception was thrown ---
2018-08-09T09:06:04.0578597Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-08-09T09:06:04.0578857Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-08-09T09:06:04.0579088Z    at MongoDB.Driver.Core.Clusters.Cluster.<SelectServerAsync>d__43.MoveNext()
2018-08-09T09:06:04.0579303Z --- End of stack trace from previous location where exception was thrown ---
2018-08-09T09:06:04.0579791Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-08-09T09:06:04.0580027Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-08-09T09:06:04.0580245Z    at MongoDB.Driver.MongoClient.<AreSessionsSupportedAfterSeverSelctionAsync>d__37.MoveNext()
2018-08-09T09:06:04.0580455Z --- End of stack trace from previous location where exception was thrown ---
2018-08-09T09:06:04.0580694Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-08-09T09:06:04.0580901Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-08-09T09:06:04.0581107Z    at MongoDB.Driver.MongoClient.<AreSessionsSupportedAsync>d__34.MoveNext()
2018-08-09T09:06:04.0581326Z --- End of stack trace from previous location where exception was thrown ---
2018-08-09T09:06:04.0581817Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-08-09T09:06:04.0582028Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-08-09T09:06:04.0582227Z    at MongoDB.Driver.MongoClient.<StartImplicitSessionAsync>d__26.MoveNext()
2018-08-09T09:06:04.0582406Z --- End of stack trace from previous location where exception was thrown ---
2018-08-09T09:06:04.0582762Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-08-09T09:06:04.0582941Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-08-09T09:06:04.0583294Z    at MongoDB.Driver.MongoCollectionImpl`1.<UsingImplicitSessionAsync>d__91`1.MoveNext()
2018-08-09T09:06:04.0583494Z --- End of stack trace from previous location where exception was thrown ---
2018-08-09T09:06:04.0583670Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2018-08-09T09:06:04.0584382Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-08-09T09:06:04.0584581Z    at MongoDB.Driver.MongoCollectionBase`1.<InsertOneAsync>d__64.MoveNext()
2018-08-09T09:06:04.1605265Z 2018-08-09T09:06:04.159+0000 I CONTROL  [initandlisten] MongoDB starting : pid=3112 port=27020 dbpath=C:\Users\XXX\AppData\Local\Temp\xdol0kvu.gus34704c47a97744dda37b_27020 64-bit host=factoryvm-az49

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 39 (14 by maintainers)

Most upvoted comments

All of our tests have the same structure:

[Fact]
public async Task adds_modified_HistoryEntry()
{
    using (var runner = MongoDbRunner.Start())
    {
        var client = new MongoClient(runner.ConnectionString);
        var database = client.GetDatabase(Guid.NewGuid().ToString());
        // test code here
    }
}

For anyone who has found this issue recently, I can confirm that at least version 2.2.16 works, but some later versions (eg 3.1.3) do not.

Ok, but I have that error on my local machine when I’m running tests with dotnet test command. So it cannot be error for only VSTS hosted agents.

If it helps I have 100+ tests that use Mongo2Go package.

nothing special I guess:

netcoreapp2.2

deps: image

Base class for every integration test:

public class MongoIntegrationTest<T> : IDisposable
{
    private readonly string _databaseName = "IntegrationTest";
    internal IMongoCollection<T> Collection;
    protected IMongoDatabase Database;
    internal MongoDbRunner Runner;

    internal void CreateConnection(string collectionName)
    {
        CreateConnection();
        Collection = Database.GetCollection<T>(collectionName);
    }

    internal void CreateConnection()
    {
        MongoConfigurator.Initialize();
        Runner = MongoDbRunner.Start();

        var client = new MongoClient(Runner.ConnectionString);
        Database = client.GetDatabase(_databaseName);
    }

    internal void SeedCollection(string collection, string fileName)
    {
        var path = AppContext.BaseDirectory + "../../../../DatabaseSeeds/" + fileName;
        Runner.Import(_databaseName, collection, path, true);
    }

    internal void SetMongoConnection(AutoMock mock)
    {
        mock.Provide(Database);    
    }

    public void Dispose()
    {
        Runner?.Dispose();
    }
}

and example test class:

public class CommentRepositoryTests : MongoIntegrationTest<Comment>
{
    
    [Fact]
    public async Task it_should_be_possible_to_add_and_retrieve_comment()
    {
        CreateConnection(TestConstants.CommentsCollectionName);
        var comment = TestComments.One;
        
        using (var mock = AutoMock.GetLoose())
        {
            SetMongoConnection(mock);
            var repo = mock.Create<CommentRepository>();
            
            await repo.AddAsync(comment);
            var foundComment = await repo.GetOrFailAsync(comment.Id);
            
            foundComment.Should().BeEquivalentTo(comment);
        }
        Runner.Dispose();
    }  
}

task configuration on azure devops:

task: DotNetCoreCLI@2
    displayName: Test
    inputs:
      command: test
      projects: '**/*Tests/*.csproj'
      arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Exclude="[xunit.*]*"'

I’m going to close this issue and declare that Mongo2Go is NOT compatible with VSTS / Azure DevOps. see https://stackoverflow.com/a/44662712

If you’re using the hosted agent, you can’t open up ports or change anything about the machine’s configuration. You’ll need to set up your own agent for builds

Mongo2Go must open ports. If this is not possible, then there is absolutely no chance that we will get this up and running.

Should that example have a static field? It seems odd to dispose of a static field in a subclass’s instance method.

I think the problem may be related with .net core. Try to run them against net461. See: https://github.com/Mongo2Go/Mongo2Go/issues/48

@ppumkin It’s time to clone the repo and debug this! 😉

Sorry for the misinformation. We have the same problem on VSTS agents hosted on Windows and Ubuntu, and also on local machines. The same exception in all cases.

No, Mac (#43) and Linux (#47) works now super fine. I tested both successfully.

I have absolutely no clue what happens on VSTS and really hope some user figures out what’s wrong. Unfortunately VSTS is pretty 💩, because you can’t even login to the agent… Also, time is rare here, too. 😞