anchor.diff:  let log = LogManager.GetLogger "Ormonit.Test"
   let logConfig = NLog.Config.LoggingConfiguration()
   let consoleTarget = new NLog.Targets.ColoredConsoleTarget()
  +
   logConfig.AddTarget("console", consoleTarget)
  +
   let fileTarget = new NLog.Targets.FileTarget()
  +
   logConfig.AddTarget("file", fileTarget)
   consoleTarget.Layout <- Layout.FromString @"${date:format=HH\:mm\:ss}|${logger}|${message}"
   fileTarget.FileName <- Layout.FromString @"${basedir}\logs\Ormonit.ServiceTest.log"
  
positive.code:     lock mlock (fun () -> continu <- false)
      task.Wait()
      log.Info("[{0}] Ormonit test exit.", lid)
  
  
  
negative.code:     assert (s >= 0)
      let eid = NN.Connect(s, ca)
      assert (eid >= 0)
      let rec recvloop() = 
          //let mutable buff : byte[] = null '\000'
          //log.Info("[{0}] Ormonit test receive (blocking).", lid)
          match recv s with
          | Error(errn, errm) -> 
              sprintf """[%i] Error %i (recv). %s.""" lid errn errm |> log.Error
              recvloop()
          | Msg(_, note) -> 
              let nparts = note.Split([| ' ' |], StringSplitOptions.RemoveEmptyEntries)
              
              let cmd = 
                  if nparts.Length > 0 then nparts.[0]
                  else String.Empty
              
              let args = 
                  List.ofArray (if nparts.Length > 1 then nparts.[1..]
                                else [||])
              
              //let parsed = Cli.parseArgs args
              sprintf "[%i] Ormonit test \"%s\" note received. (%s)" lid note cmd |> log.Info
              match cmd with
              | "close" -> 
                  let flag = 
                      lock mlock (fun () -> 
                          continu <- false
                          continu)
                  //log.Trace("""[{0}] Processing "close" notification. continue value {1}""", lid, flag)
                  log.Trace("""[{0}] Sending "close" aknowledgement.""", lid)
                  match Msg(config.["ckey"], "closing") |> send s with
                  | Error(errn, errm) -> 
                      sprintf """Error %i (send). %s.""" errn errm |> log.Error
                      recvloop()
                  | Msg _ -> ()
              //log.Trace("""[{0}] Sent "close" aknowledgement.""", lid)
              | "report-status" -> 
                  let rand = Random().NextDouble()
                  if rand > 0.8 then 
                      //log.Trace("""[{0}] Processing "report-status" command.""", lid)
                      log.Trace("""[{0}] Sending "report-status" aknowledgement.""", lid)
                      match Msg(config.["ckey"], "ok") |> send s with
                      | Error(errn, errm) -> sprintf """Error %i (send). %s.""" errn errm |> log.Error
                      | Msg _ -> ()
                  //log.Trace("""[{0}] Sent "report-status" aknowledgement.""", lid)
                  else log.Warn("""[{0}] Processing "report-status" failed (simulated).""", lid)
                  recvloop()
              | "sys:client-key" -> 
                  log.Trace("[{0}] Sending client-key: '{1}'.", lid, config.["ckey"])
                  let encrypted = encrypt config.["publicKey"] config.["ckey"]
                  let note = Convert.ToBase64String(encrypted)
                  match Msg(lid.ToString(), note) |> send s with
                  | Error(errn, errm) -> sprintf """Error %i (send). %s.""" errn errm |> log.Error
                  | Msg _ -> log.Trace("[{0}] Sent client-key: '{1}'.", lid, config.["ckey"])
                  recvloop()
              | _ -> recvloop()
      recvloop()
      assert (NN.Shutdown(s, eid) = 0)
      assert (NN.Close(s) = 0)
  
  let rec private action() = 
      //log.Trace("[{0}] Ormonit test action enter", lid)
      match lock mlock (fun () -> continu) with
      | false -> 
          //log.Trace("continue value {0}", continu)
          log.Trace("[{0}] Ormonit test action exit", lid)
      | true -> 
          //simulate long running task 1-5s
          let t = Random().Next(1000, 5000)
          log.Trace("[{0}] Ormonit test action blocking for {1}ms", lid, t)
  