#define __PRETTY_FUNCTION__ __func__
#endif
+#define YATL_STRINGIFY(x) #x
+#define YATL_TOSTRING(x) YATL_STRINGIFY(x)
+#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__)
+#define YATL_AT_PARAM __func__, AT
+#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique"
+#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func"
+
#define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__
namespace libtest {
{
private:
public:
- Gearmand(const std::string& host_arg, in_port_t port_arg) :
- libtest::Server(host_arg, port_arg, GEARMAND_BINARY, true)
- {
- set_pid_file();
- }
+ Gearmand(const std::string& host_arg, in_port_t port_arg, const char* binary= GEARMAND_BINARY);
bool ping()
{
gearman_client_free(client);
return true;
}
- Error << hostname().c_str() << ":" << port() << " was " << gearman_strerror(rc) << " extended: " << gearman_client_error(client);
+
+ if (out_of_ban_killed() == false)
+ {
+ Error << hostname().c_str() << ":" << port() << " was " << gearman_strerror(rc) << " extended: " << gearman_client_error(client);
+ }
}
else
{
bool build(size_t argc, const char *argv[]);
};
+Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, const char* binary_arg) :
+ libtest::Server(host_arg, port_arg, binary_arg, true)
+{
+ set_pid_file();
+}
+
bool Gearmand::build(size_t argc, const char *argv[])
{
if (getuid() == 0 or geteuid() == 0)
return new Gearmand(hostname, try_port);
}
+libtest::Server *build_gearmand(const char *hostname, in_port_t try_port, const char* binary)
+{
+ return new Gearmand(hostname, try_port, binary);
+}
+
}
libtest::Server *build_gearmand(const char *hostname, in_port_t try_port);
+libtest::Server *build_gearmand(const char *hostname, in_port_t try_port, const char* binary);
+
}
std::cerr << "std::exception:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
}
+ catch (char const*)
+ {
+ std::cerr << "Exception:" << std::endl;
+ exit_code= EXIT_FAILURE;
+ }
catch (...)
{
std::cerr << "Unknown exception halted execution." << std::endl;
libtest::Server(host_arg, port_arg,
MEMCACHED_BINARY, is_memcached_libtool(), is_socket_arg)
{
+ set_pid_file();
}
virtual const char *sasl() const
return _username;
}
- virtual bool has_pid_file() const
+ bool wait_for_pidfile() const
{
- return false;
+ Wait wait(pid(), 4);
+
+ return wait.successful();
}
bool ping()
{
+#if 0
+ // Memcached is slow to start, so we need to do this
+ if (pid_file().empty() == false)
+ {
+ if (wait_for_pidfile() == false)
+ {
+ Error << "Pidfile was not found:" << pid_file() << " :" << running();
+ return -1;
+ }
+ }
+#endif
+
memcached_return_t rc;
bool ret;
libtest::Server *build_memcached_sasl_socket(const std::string& socket_file, const in_port_t try_port, const std::string& username, const std::string& password);
}
+
_is_socket(is_socket_arg),
_port(port_arg),
_hostname(host_arg),
- _app(executable, _is_libtool)
+ _app(executable, _is_libtool),
+ out_of_ban_killed_(false)
{
}
{
_app.slurp();
_app.check();
-
return true;
}
bool Server::args(Application& app)
{
+
// Set a log file if it was requested (and we can)
if (has_log_file_option())
{
bool validate();
+ void out_of_ban_killed(bool arg)
+ {
+ out_of_ban_killed_= arg;
+ }
+
+ bool out_of_ban_killed()
+ {
+ return out_of_ban_killed_;
+ }
+
protected:
bool set_pid_file();
Options _options;
bool set_log_file();
bool set_socket_file();
void reset_pid();
+ bool out_of_ban_killed_;
bool args(Application&);
std::string _error;
}
else
{
- char port_str[NI_MAXSERV];
+ char port_str[NI_MAXSERV]= { 0 };
snprintf(port_str, sizeof(port_str), "%u", int(arg->port()));
server_config_string+= "--server=";
bool success= true;
for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); ++iter)
{
- if ((*iter) and (*iter)->has_pid() and (*iter)->kill() == false)
+ if ((*iter)->has_pid() and (*iter)->kill() == false)
{
Error << "Unable to kill:" << *(*iter);
success= false;
}
}
}
+ else if (server_type.compare("hostile-gearmand") == 0)
+ {
+ if (GEARMAND_BINARY)
+ {
+ if (HAVE_LIBGEARMAN)
+ {
+ server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand");
+ }
+ }
+ }
else if (server_type.compare("drizzled") == 0)
{
if (DRIZZLED_BINARY)
*/
#include <config.h>
+
#include <libtest/timer.hpp>
+
#include <ctime>
+#include <iomanip>
namespace libtest {
struct timespec temp;
arg.difference(temp);
- output << temp.tv_sec;
+ if (temp.tv_sec > 60)
+ {
+ output << temp.tv_sec / 60;
+ output << "." << temp.tv_sec % 60;
+ }
+ else
+ {
+ output << temp.tv_sec;
+ }
+
output << ":";
- output << temp.tv_nsec;
+ output << std::setfill('0') << std::setw(9) << temp.tv_nsec;
return output;
}
#pragma once
+#include <cstdlib>
#include <ctime>
-#include <ostream>
+#include <iostream>
#ifdef __MACH__
# include <mach/clock.h>
_time(_end);
}
+ void offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds)
+ {
+ reset();
+ _end= _begin;
+ _end.tv_sec+= (minutes_arg * 60) +seconds_arg;
+ _end.tv_nsec+= nanoseconds;
+ }
+
+ int64_t minutes()
+ {
+ struct timespec result;
+ difference(result);
+ return int64_t(result.tv_sec / 60);
+ }
+
+ uint64_t elapsed_milliseconds() const
+ {
+ struct timespec temp;
+ difference(temp);
+
+ return temp.tv_sec*1000 +temp.tv_nsec/1000000;
+ }
+
void difference(struct timespec& arg) const
{
if ((_end.tv_nsec -_begin.tv_nsec) < 0)
{
- arg.tv_sec= _end.tv_sec -_begin.tv_sec-1;
+ arg.tv_sec= _end.tv_sec -_begin.tv_sec -1;
arg.tv_nsec= 1000000000 +_end.tv_nsec -_begin.tv_nsec;
}
return TEST_SUCCESS;
}
+static test_return_t Timer_TEST(void *)
+{
+ int64_t minutes= random() % 50;
+ minutes++;
+
+ Timer check;
+
+ check.reset();
+ check.offset(minutes, 2, 200);
+
+ test_compare(check.minutes(), minutes);
+
+ return TEST_SUCCESS;
+}
+
static test_return_t lookup_true_TEST(void *)
{
test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working");
{0, 0, 0}
};
+test_st timer_TESTS[] ={
+ {"libtest::Timer", 0, Timer_TEST },
+ {0, 0, 0}
+};
+
test_st dns_TESTS[] ={
{"libtest::lookup(true)", 0, lookup_true_TEST },
{"libtest::lookup(false)", 0, lookup_false_TEST },
{"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
{"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
{"dns", 0, 0, dns_TESTS },
+ {"libtest::Timer", 0, 0, timer_TESTS },
{0, 0, 0, 0}
};