CoreyKaylor / Lightning.NET

.NET library for LMDB key-value store
Other
398 stars 82 forks source link

LightningDB.Tests/MultiProcessTests.cs - can_load_environment_from_multiple_processes() - appdomains are inproc (not separate process) #102

Closed simonweijgers closed 4 years ago

simonweijgers commented 7 years ago

LightningDB.Tests/MultiProcessTests.cs doesn't test loading from multiple processes but from same process (multiple .Net AppDomains are contained within the same OS process).

The following illustrates this:

  1. Create file called secondapp.fsx with following contents:

    type secondapp () =
    do System.Console.WriteLine("Hello from second app, my PID is: " + string(System.Diagnostics.Process.GetCurrentProcess().Id))
  2. Compile to dll: fsc.exe secondapp.fsx --target:library

  3. Create firstapp.fsx with following contents:

    
    #r "secondapp.dll"

System.Console.WriteLine("Hello from first app, my PID is: " + string(System.Diagnostics.Process.GetCurrentProcess().Id))

let secondDomain = System.AppDomain.CreateDomain("2nd Process") let secondAppType = typeof

let app = secondDomain.CreateInstanceFromAndUnwrap("secondapp.dll", secondAppType.FullName); System.Threading.Thread.Sleep(5000)


4. Run firsapp.fsx: fsi.exe firstapp.fsx

5. Output:

Hello from first app, my PID is: 8168 Hello from second app, my PID is: 8168


---------

There's two points I'd make:

1. can_load_environment_from_multiple_processes is not testing what it appears to want to test
2. the scenario it does test (multiple appdomains opening same lmdb environment) is explicitly not supported, see http://www.lmdb.tech/doc/starting.html#thrproc ("...  Otherwise, if a single process opens the same environment multiple times, closing it once will remove all the locks held on it, and the other instances will be vulnerable to corruption from other processes.")
CoreyKaylor commented 7 years ago

Yep, good find. Whenever I have time to spend I'll take a look at reworking that test. Happy to pull in a PR in the meantime.

CoreyKaylor commented 4 years ago

Closed by 1d334ef

The test is still disabled due to issues on Linux, but passes on OSX and Windows. You can comment out the skip to try out, but this demonstrates a more sound approach to the multi-process example.