From 40007155d53de2a60a720916c5f75681f72fedf5 Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Wed, 15 Aug 2018 12:47:07 +0200
Subject: [PATCH] use mongo without nomad for restart test

---
 CMakeModules/prepare_asapo.cmake              |  1 -
 config/nomad/mongo.nmd.in                     | 53 -------------------
 .../dummy_data_producer.cpp                   |  2 +-
 .../check_mongo_restart/check_linux.sh        | 21 +++++---
 4 files changed, 16 insertions(+), 61 deletions(-)
 delete mode 100644 config/nomad/mongo.nmd.in

diff --git a/CMakeModules/prepare_asapo.cmake b/CMakeModules/prepare_asapo.cmake
index 449796fbd..17681e5bd 100644
--- a/CMakeModules/prepare_asapo.cmake
+++ b/CMakeModules/prepare_asapo.cmake
@@ -11,7 +11,6 @@ function(prepare_asapo)
         configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver.json.tpl.lin receiver.json.tpl COPYONLY)
     endif()
     configure_file(${CMAKE_SOURCE_DIR}/config/nomad/receiver.nmd.in  receiver.nmd @ONLY)
-    configure_file(${CMAKE_SOURCE_DIR}/config/nomad/mongo.nmd.in  mongo.nmd @ONLY)
     configure_file(${CMAKE_SOURCE_DIR}/config/nomad/discovery.nmd.in  discovery.nmd @ONLY)
     configure_file(${CMAKE_SOURCE_DIR}/config/nomad/authorizer.nmd.in  authorizer.nmd @ONLY)
     configure_file(${CMAKE_SOURCE_DIR}/config/nomad/broker.nmd.in  broker.nmd @ONLY)
diff --git a/config/nomad/mongo.nmd.in b/config/nomad/mongo.nmd.in
deleted file mode 100644
index cdac5fe4a..000000000
--- a/config/nomad/mongo.nmd.in
+++ /dev/null
@@ -1,53 +0,0 @@
-job "mongo" {
-  datacenters = ["dc1"]
-
-  group "mongo" {
-    count = 1
-
-    restart {
-      attempts = 2
-      interval = "3m"
-      delay = "15s"
-      mode = "delay"
-    }
-
-    task "mongo" {
-      driver = "docker"
-
-      config {
-        network_mode = "host"
-        image = "mongo:4.0.0"
-        volumes = ["/tmp/mongo:/data/db"]
-        args = ["--port","27016"]
-      }
-
-      resources {
-        cpu    = 1500
-        memory = 1256
-        network {
-          port "mongo" {
-          static = 27016
-          }
-        }
-      }
-
-      service {
-        port = "mongo"
-        name = "mongo"
-        check {
-          type     = "script"
-          name     = "alive"
-          command  = "mongo"
-          args     = ["--eval","db.version()"]
-          interval = "10s"
-          timeout  = "5s"
-        }
-        check_restart {
-          limit = 2
-          grace = "90s"
-          ignore_warnings = false
-        }
-      }
-    }
-  }
-}
diff --git a/examples/producer/dummy-data-producer/dummy_data_producer.cpp b/examples/producer/dummy-data-producer/dummy_data_producer.cpp
index 87ca3582c..0e49d91c3 100644
--- a/examples/producer/dummy-data-producer/dummy_data_producer.cpp
+++ b/examples/producer/dummy-data-producer/dummy_data_producer.cpp
@@ -94,7 +94,7 @@ std::unique_ptr<asapo::Producer> CreateProducer(const Args& args) {
     }
 
     producer->EnableLocalLog(true);
-    producer->SetLogLevel(asapo::LogLevel::Info);
+    producer->SetLogLevel(asapo::LogLevel::Debug);
     return producer;
 }
 
diff --git a/tests/automatic/producer_receiver/check_mongo_restart/check_linux.sh b/tests/automatic/producer_receiver/check_mongo_restart/check_linux.sh
index 926b36389..52e5f2a5c 100644
--- a/tests/automatic/producer_receiver/check_mongo_restart/check_linux.sh
+++ b/tests/automatic/producer_receiver/check_mongo_restart/check_linux.sh
@@ -6,7 +6,7 @@ trap Cleanup EXIT
 
 function wait_mongo {
 NEXT_WAIT_TIME=0
-until mongo --port 27016 --eval "db.version()" | tail -1 | grep 4.0.0 || [ $NEXT_WAIT_TIME -eq 30 ]; do
+until mongo --port 27016 --eval "db.version()" | tail -2 | grep version || [ $NEXT_WAIT_TIME -eq 30 ]; do
   echo "Wait for mongo"
   NEXT_WAIT_TIME=$(( NEXT_WAIT_TIME++ ))
   sleep 1
@@ -18,6 +18,11 @@ fi
 }
 
 
+function kill_mongo {
+    kill -9 `ps xa | grep mongod | grep 27016 | awk '{print $1;}'`
+}
+
+
 database_name=db_test
 beamtime_id=asapo_test
 beamline=test
@@ -29,11 +34,13 @@ Cleanup() {
     nomad stop authorizer
     nomad stop nginx
     echo "db.dropDatabase()" | mongo --port 27016 ${beamtime_id}
-    nomad stop mongo
+    kill_mongo
 }
 
-nomad run mongo.nmd
+mongod --dbpath /tmp/mongo --port 27016 --logpath /tmp/mongolog --fork
 wait_mongo
+
+
 # create db before worker starts reading it. todo: git rid of it
 echo "db.${beamtime_id}.insert({dummy:1})" | mongo --port 27016 ${beamtime_id}
 
@@ -52,10 +59,12 @@ nfiles=1000
 
 $1 localhost:8400 ${beamtime_id} 100 $nfiles 1  0 200 &
 
-sleep 0.1
+sleep 0.5
+
+kill_mongo
+sleep 3
+mongod --dbpath /tmp/mongo --port 27016 --logpath /tmp/mongolog --fork
 
-docker rm -f  `docker ps | grep mongo | awk '{print $1;}'`
-sleep 1
 
 wait
 
-- 
GitLab