Skip to content

Commit

Permalink
HTCONDOR-934 Add regression test
Browse files Browse the repository at this point in the history
Also de-glob condor_unit_tests CMakeLists, so that this
change doesn't break everyone else
  • Loading branch information
GregThain authored and sergey-komissarov committed Jan 19, 2022
1 parent 9d38c73 commit 4f58863
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/condor_unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,40 @@
#
###############################################################

file(GLOB FTSrcs "FTEST_*.cpp")
file(GLOB OTSrcs "OTEST_*.cpp")

set( FTSrcs
FTEST_basename.cpp
FTEST_dirname.cpp
FTEST_flatten_and_inline.cpp
FTEST_fullpath.cpp
FTEST_getHostFromAddr.cpp
FTEST_getPortFromAddr.cpp
FTEST_host_in_domain.cpp
FTEST_is_valid_sinful.cpp
FTEST_stl_string_utils.cpp
FTEST_string_to_port.cpp
FTEST_strlwr.cpp
FTEST_strupr.cpp
FTEST_tokener.cpp
FTEST_your_string.cpp
)
set( OTSrcs
OTEST_ArgList.cpp
OTEST_condor_sockaddr.cpp
OTEST_Directory.cpp
OTEST_Env.cpp
OTEST_FileLock.cpp
OTEST_HashTable.cpp
OTEST_Iso_Dates.cpp
OTEST_MyString.cpp
OTEST_Old_Classads.cpp
OTEST_ranger.cpp
OTEST_StatInfo.cpp
OTEST_StringList.cpp
OTEST_Timeslice.cpp
OTEST_TmpDir.cpp
OTEST_UserPolicy.cpp
)

# old style condor unit tests that all link into a single huge exe
condor_exe_test(condor_unit_tests "${FTSrcs};${OTSrcs};emit.cpp;function_test_driver.cpp;unit_test_utils.cpp;unit_tests.cpp" "${CONDOR_TOOL_LIBS};${CONDOR_WIN_LIBS}")
Expand Down
68 changes: 68 additions & 0 deletions src/condor_unit_tests/OTEST_Timeslice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/***************************************************************
*
* Copyright (C) 1990-2022, Condor Team, Computer Sciences Department,
* University of Wisconsin-Madison, WI.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************/

/*
This code tests the functions within condor_utils/condor_timslice.h.
*/

#include "condor_common.h"
#include "condor_debug.h"
#include "condor_config.h"
#include "function_test_driver.h"
#include "emit.h"
#include "unit_test_utils.h"
#include "condor_timeslice.h"

static bool test_always_runs_first_time(void);

//Global variables

bool OTEST_Timeslice(void) {
emit_object("Timeslice");
emit_comment("This tests the timeslice object");

// driver to run the tests and all required setup
FunctionDriver driver;
driver.register_function(test_always_runs_first_time);

// run the tests
return driver.do_all_functions();
}

static bool test_always_runs_first_time() {
emit_test("Test that timeslice object always runs when initialized");

emit_input_header();
time_t startTime = time(0);

// This code use to fail when gettimeofday returns
// tv_usec close to 0. Give it 20 seconds to try
// to hit this race condition
while (time(0) - startTime < 20) {
Timeslice ts;
ts.setTimeslice(0.01);
int avoid_time = 3600;
ts.setMaxInterval(avoid_time);
ts.setInitialInterval(0);
if (!ts.isTimeToRun()) {
FAIL;
}
}
PASS;
}
2 changes: 2 additions & 0 deletions src/condor_unit_tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool OTEST_TmpDir(void);
bool OTEST_StatInfo(void);
bool OTEST_condor_sockaddr();
bool OTEST_ranger();
bool OTEST_Timeslice();

// function map that maps testing function names to testing functions
const static struct {
Expand Down Expand Up @@ -98,6 +99,7 @@ const static struct {
map(OTEST_StatInfo),
map(OTEST_condor_sockaddr),
map(OTEST_ranger),
map(OTEST_Timeslice),
};
int function_map_num_elems = sizeof(function_map) / sizeof(function_map[0]);

Expand Down

0 comments on commit 4f58863

Please sign in to comment.