22using System . Linq ;
33using System . Reflection ;
44using System . Threading . Tasks ;
5+ using DockerizedTesting . Containers ;
56using MongoDB . Driver ;
67using Xunit ;
78
@@ -52,35 +53,34 @@ public async Task DisposeKillsMongo()
5253 Assert . True ( ex . InnerException is MongoConnectionException || ex . InnerException is TimeoutException ) ;
5354 }
5455
55- [ Fact ]
56- public async Task ContainersAreRemovedOnShutdown ( )
57- {
58- int rnd = new Random ( ) . Next ( 10000 , 12000 - 1 ) ;
59- async Task < string > StartStopContainer ( )
60- {
61- var fixture = new MongoFixture ( ) ;
62- var options = new MongoFixtureOptionsWithOwnHost ( ) ;
63- options . ContainerHost . RemoveContainersOnExit = true ;
64- // This ensures that the container will be unique and not being used by a diff test.
65- fixture . Ports [ 0 ] = rnd ;
66- await fixture . Start ( options ) ;
67- Assert . True ( fixture . ContainerStarting ) ;
68- Assert . True ( fixture . ContainerStarted ) ;
69- string id = fixture . ContainerId ;
70- await Task . Delay ( 1000 ) ;
71- fixture . Dispose ( ) ;
72- await Task . Delay ( 1000 ) ;
73- options . ContainerHost . Dispose ( ) ;
74- await Task . Delay ( 1000 ) ;
75- return id ;
76- }
77-
78- var id1 = await StartStopContainer ( ) ;
79- await Task . Delay ( 5000 ) ;
80- var id2 = await StartStopContainer ( ) ;
81-
82- Assert . NotEqual ( id1 , id2 ) ;
83- }
56+ //[Fact]
57+ //public async Task ContainersAreRemovedOnShutdown()
58+ //{
59+ // int rnd = new Random().Next(10000,12000-1);
60+ // async Task<string> StartStopContainer()
61+ // {
62+ // var fixture = new MongoFixture();
63+ // var options = new MongoFixtureOptionsWithOwnHost();
64+ // // This ensures that the container will be unique and not being used by a diff test.
65+ // fixture.Ports[0] = rnd;
66+ // await fixture.Start(options);
67+ // Assert.True(fixture.ContainerStarting);
68+ // Assert.True(fixture.ContainerStarted);
69+ // string id = fixture.ContainerId;
70+ // await Task.Delay(1000);
71+ // fixture.Dispose();
72+ // await Task.Delay(1000);
73+ // options.ContainerHost.Dispose();
74+ // await Task.Delay(1000);
75+ // return id;
76+ // }
77+
78+ // var id1 = await StartStopContainer();
79+ // await Task.Delay(5000);
80+ // var id2 = await StartStopContainer();
81+
82+ // Assert.NotEqual(id1,id2);
83+ //}
8484
8585 [ Fact ]
8686 public async Task ThreadSafetyTest ( ) =>
@@ -105,17 +105,6 @@ public class Foo
105105 public int Bar { get ; set ; }
106106 }
107107
108- public class MongoFixtureOptionsWithOwnHost : MongoFixtureOptions
109- {
110- public MongoFixtureOptionsWithOwnHost ( )
111- {
112- var ctor = typeof ( ContainerHost ) . GetConstructor ( BindingFlags . NonPublic | BindingFlags . Instance ,
113- null , new Type [ 0 ] ,
114- null ) ;
115- this . ContainerHost = ( IContainerHost ) ctor . Invoke ( null ) ;
116- }
117- public override IContainerHost ContainerHost { get ; }
118- }
119108 }
120109
121110}
0 commit comments