asimmon / ephemeral-mongo

EphemeralMongo is a set of three NuGet packages wrapping the binaries of MongoDB 4, 5 and 6 built for .NET Standard 2.0.
Apache License 2.0
105 stars 14 forks source link

"Text file busy" on relaunch #33

Closed henaff closed 1 year ago

henaff commented 1 year ago

The first time i launch my tests, the package works perfectly. But then if i relaunch my tests i get:

/usr/lib/dotnet/sdk/6.0.116/Microsoft.Common.CurrentVersion.targets(4812,5): error MSB3027: Could not copy "/home/user/.nuget/packages/ephemeralmongo6.runtime.linux-x64/1.0.0/runtimes/linux-x64/native/mongodb/bin/mongod" to "bin/Debug/net6.0/runtimes/linux-x64/native/mongodb/bin/mongod". Exceeded retry count of 10. Failed.  [/home/user/Desktop/Sources/Project/source/back/Project/Project.PublicBo.Api.Tests/Project.PublicBo.Api.Tests.csproj]
/usr/lib/dotnet/sdk/6.0.116/Microsoft.Common.CurrentVersion.targets(4812,5): error MSB3021: Unable to copy file "/home/user/.nuget/packages/ephemeralmongo6.runtime.linux-x64/1.0.0/runtimes/linux-x64/native/mongodb/bin/mongod" to "bin/Debug/net6.0/runtimes/linux-x64/native/mongodb/bin/mongod". Text file busy : '/home/user/Desktop/Sources/Project/source/back/Project/Project.PublicBo.Api.Tests/bin/Debug/net6.0/runtimes/linux-x64/native/mongodb/bin/mongod' [/home/user/Desktop/Sources/Project/source/back/Project/Project.PublicBo.Api.Tests/Project.PublicBo.Api.Tests.csproj]
henaff commented 1 year ago

A workaround is to run dotnet clean each time before running tests

asimmon commented 1 year ago

Hi @henaff , the MongoDB executables are copied at build time and a few minutes ago I've changed the CopyToOutputDirectory value from Always to PreserveNewest, so that might help to prevent copying files for nothing (see 1.1.2).

However, it your mongod process in your bin/ directory is still being used, it means that the process was not correctly disposed. You must dispose the IMongoRunner that you get when calling MongoRunner.Run, and try to reuse it as much as you can in your test project.