You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As promised, here is a bug report demonstrating thread unsafe-ness of coolprop using sharpfluids.
I made an xunit test:
dotnet new xunit --output threadSafetyTestSharpFluids
and i made two identical unit tests and placed them under two files:
UnitTest1.cs
UnitTest2.cs
Here are the codes for each unit test respectively.
usingEngineeringUnits;usingEngineeringUnits.Units;usingSharpFluids;usingXunit;usingSystem;usingXunit.Abstractions;namespacetherminolPipeTest;publicclassUnitTest1{[Theory][InlineData(20,1064)][InlineData(30,1056)][InlineData(40,1048)][InlineData(50,1040)][InlineData(60,1032)][InlineData(70,1024)][InlineData(80,1015)][InlineData(90,1007)][InlineData(100,999)][InlineData(110,991)][InlineData(120,982)][InlineData(130,974)][InlineData(140,965)][InlineData(150,957)][InlineData(160,948)][InlineData(180,931)]publicvoidWhenTherminolObjectTestedExpectVendorDensityValue(doubletemperatureC,doubledensityValueKgPerM3){//Setup// set temperature and pressure for dowtherm and TherminolPressurereferencePressure=newPressure(1.1013e5,PressureUnit.Pascal);EngineeringUnits.TemperaturetestTemperature=newEngineeringUnits.Temperature(temperatureC,TemperatureUnit.DegreeCelsius);// get therminol VP-1 fluid objectFluidtherminol=newFluid(FluidList.InCompTherminolVP1);// Acttherminol.UpdatePT(referencePressure,testTemperature);DensityresultDensity=therminol.Density;// Assert //// Check if densities are equal to within 0.2% of vendor datadoubleerrorMax=0.2/100;doubleresultDensityValueKgPerM3=resultDensity.As(DensityUnit.KilogramPerCubicMeter);doubleerror=Math.Abs(resultDensityValueKgPerM3-densityValueKgPerM3)/densityValueKgPerM3;if(error<errorMax){return;}if(error>errorMax){Assert.Equal(densityValueKgPerM3,resultDensity.As(DensityUnit.KilogramPerCubicMeter),0);}}}
And,
usingEngineeringUnits;usingEngineeringUnits.Units;usingSharpFluids;usingXunit;usingSystem;usingXunit.Abstractions;namespacetherminolPipeTest;publicclassUnitTest2{[Theory][InlineData(20,1064)][InlineData(30,1056)][InlineData(40,1048)][InlineData(50,1040)][InlineData(60,1032)][InlineData(70,1024)][InlineData(80,1015)][InlineData(90,1007)][InlineData(100,999)][InlineData(110,991)][InlineData(120,982)][InlineData(130,974)][InlineData(140,965)][InlineData(150,957)][InlineData(160,948)][InlineData(180,931)]publicvoidWhenTherminolObjectTestedExpectVendorDensityValue(doubletemperatureC,doubledensityValueKgPerM3){//Setup// set temperature and pressure for dowtherm and TherminolPressurereferencePressure=newPressure(1.1013e5,PressureUnit.Pascal);EngineeringUnits.TemperaturetestTemperature=newEngineeringUnits.Temperature(temperatureC,TemperatureUnit.DegreeCelsius);// get therminol VP-1 fluid objectFluidtherminol=newFluid(FluidList.InCompTherminolVP1);// Acttherminol.UpdatePT(referencePressure,testTemperature);DensityresultDensity=therminol.Density;// Assert //// Check if densities are equal to within 0.2% of vendor datadoubleerrorMax=0.2/100;doubleresultDensityValueKgPerM3=resultDensity.As(DensityUnit.KilogramPerCubicMeter);doubleerror=Math.Abs(resultDensityValueKgPerM3-densityValueKgPerM3)/densityValueKgPerM3;if(error<errorMax){return;}if(error>errorMax){Assert.Equal(densityValueKgPerM3,resultDensity.As(DensityUnit.KilogramPerCubicMeter),0);}}}
Now running both of these using dotnet watch test yields:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.ApplicationException: FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (System.ApplicationException: This backend does not implement calc_phase function)
---> System.ApplicationException: calc_compressibility_factor is not implemented for this backend
--- End of inner exception stack trace ---
at CoolPropPINVOKE64.SWIGPendingException.Set(Exception e)
at CoolPropPINVOKE64.SWIGExceptionHelper.SetPendingApplicationException(String message)
Test Run Aborted with error System.Exception: One or more errors occurred.
---> System.Exception: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.ReadByte()
at System.IO.BinaryReader.Read7BitEncodedInt()
at System.IO.BinaryReader.ReadString()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken) --- End of inner exception stack trace ---.watch : Exited with error code 1watch : Waiting for a file to change before restarting dotnet...
This happens with almost absolute certainty.
If you put the same classes in the same unit test, it will also throw some sort of race condition like error.
In fat i've gotten
Test host process crashed: malloc(): unaligned tcache chunk detected
So this can show that coolprop is definitely not thread safe.
How to solve it? I haven't quite thought of it lol... It's just quite the headache now.
The text was updated successfully, but these errors were encountered:
Hi MadsKirkFoged,
As promised, here is a bug report demonstrating thread unsafe-ness of coolprop using sharpfluids.
I made an xunit test:
and i made two identical unit tests and placed them under two files:
UnitTest1.cs
UnitTest2.cs
Here are the codes for each unit test respectively.
And,
Now running both of these using dotnet watch test yields:
This happens with almost absolute certainty.
If you put the same classes in the same unit test, it will also throw some sort of race condition like error.
In fat i've gotten
Test host process crashed: malloc(): unaligned tcache chunk detected
So this can show that coolprop is definitely not thread safe.
How to solve it? I haven't quite thought of it lol... It's just quite the headache now.
The text was updated successfully, but these errors were encountered: