TaskWatchDogTest.cpp 2.98 KB
Newer Older
1
2
/*
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2003-2021 CERN
4
5
6
7
 * @license        This program is free software: you can redistribute it and/or modify
 *                 it under the terms of the GNU General Public License as published by
 *                 the Free Software Foundation, either version 3 of the License, or
 *                 (at your option) any later version.
8
 *
9
10
11
12
 *                 This program is distributed in the hope that it will be useful,
 *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
 *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *                 GNU General Public License for more details.
13
 *
14
15
16
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17
18
19
20

#include "castor/tape/tapeserver/daemon/TaskWatchDog.hpp"
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
#include "castor/messages/TapeserverProxyDummy.hpp"
Victor Kotlyar's avatar
Victor Kotlyar committed
21
#include "common/log/StringLogger.hpp"
22
#include "scheduler/TapeMountDummy.hpp"
23
24

#include <gmock/gmock.h>
25
26
#include <gtest/gtest.h>

27

28
29
30
31
32
namespace unitTests {
  using namespace castor::tape;
  using ::testing::_;
  
TEST(castor_tape_tapeserver_daemon, WatchdogTestStuckWithNothing) {
33
34
35
  const double periodToReport = 10; // We wont report in practice
  const double stuckPeriod = 0.01;
  const double pollPeriod = 0.01;
36
  
37
  cta::log::StringLogger log("dummy","castor_tape_tapeserver_daemon_WatchdogTestStuck",cta::log::DEBUG);
Victor Kotlyar's avatar
Victor Kotlyar committed
38
  cta::log::LogContext lc(log);
39
40
  
  castor::messages::TapeserverProxyDummy dummyInitialProcess;
41
  cta::TapeMountDummy dummyTapeMount;
42
43

  tapeserver::daemon::RecallWatchDog watchdog(periodToReport,
44
    stuckPeriod,dummyInitialProcess,dummyTapeMount,"testTapeDrive",lc,pollPeriod);
45
46
  
  watchdog.startThread();
47
  usleep(100000);
48
  watchdog.stopAndWaitThread();
49
50
51
  //we dont tell the watchdog we are working on file, 
  //it should not report as being stuck
  ASSERT_EQ(std::string::npos, log.getLog().find("No tape block movement for too long"));
52
53
}

54
TEST(castor_tape_tapeserver_daemon, MigrationWatchdogTestStuck) {
55
56
57
  const double reportPeriod = 10; // We wont report in practice
  const double stuckPeriod = 0.01;
  const double pollPeriod = 0.01;
58
  
59
  cta::log::StringLogger log("dummy","castor_tape_tapeserver_daemon_WatchdogTestStuck",cta::log::DEBUG);
Victor Kotlyar's avatar
Victor Kotlyar committed
60
  cta::log::LogContext lc(log);
61
62
  
  castor::messages::TapeserverProxyDummy dummyInitialProcess;
63
  cta::TapeMountDummy dummyTapeMount;
64
  
65
  // We will poll for a 
66
  tapeserver::daemon::MigrationWatchDog watchdog(reportPeriod,stuckPeriod,
67
    dummyInitialProcess, dummyTapeMount, "testTapeDrive",  lc, pollPeriod);
68
69
  
  watchdog.startThread();
70
  watchdog.notifyBeginNewJob(64, 64);
71
  usleep(100000);
72
  watchdog.stopAndWaitThread();
73
74
  // This time the internal watchdog should have triggered
  ASSERT_NE(std::string::npos, log.getLog().find("No tape block movement for too long"));
75
76
}

Victor Kotlyar's avatar
Victor Kotlyar committed
77
}