Skip to content

Commit

Permalink
bsock_test: adapted tests for dir-sd connection
Browse files Browse the repository at this point in the history
- pointers as std:: smart pointers
- dir_to_sd_connection_test commented out
- complete build runs properly
- create_accepted_server_socket(): do not exit appllication but return -1
  • Loading branch information
franku committed Sep 20, 2018
1 parent c76c0fc commit 1d46849
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 127 deletions.
85 changes: 57 additions & 28 deletions core/src/lib/unittests/bsock_dir_sd_connection_test.cc
Expand Up @@ -19,39 +19,68 @@
02110-1301, USA.
*/
#include "bsock_test.h"
#include "create_resource.h"
#include "gtest/gtest.h"
#include "stored/socket_server.h"
#include "stored/stored_globals.h"
#include "stored/stored_conf.h"

#define DIRECTOR_DAEMON
#include "include/bareos.h"
#include "console/console_conf.h"
#include "lib/tls_openssl.h"

#include "include/jcr.h"
#include "dird/sd_cmds.h"
#include "dird/dird_globals.h"
#include "dird/dird_conf.h"
#undef DIRECTOR_DAEMON

#include <thread>

static void start_sd_server()
{
storagedaemon::me = storagedaemon::CreateAndInitializeNewStorageResource();

int newsockfd = create_accepted_server_socket(BSOCK_TEST_PORT_NUMBER);
EXPECT_GT(newsockfd, 0);
if (newsockfd < 0) {
return;
}
std::unique_ptr<BareosSocket> bs(create_new_bareos_socket(newsockfd));
storagedaemon::HandleConnectionRequest(bs.get());

delete storagedaemon::me;
storagedaemon::me = nullptr;
}

static void connect_dir_to_sd()
{
JobControlRecord jcr;
memset(&jcr, 0, sizeof(jcr));

jcr.res.wstore = directordaemon::CreateAndInitializeNewStorageResource();
jcr.res.wstore->address = (char*)"127.0.0.1";
jcr.res.wstore->SDport = BSOCK_TEST_PORT_NUMBER;

directordaemon::me = directordaemon::CreateAndInitializeNewDirectorResource();

EXPECT_TRUE(directordaemon::ConnectToStorageDaemon(&jcr, 1, 1, true));

delete jcr.res.wstore;
jcr.res.wstore = nullptr;

delete directordaemon::me;
directordaemon::me = nullptr;
}

//static void start_sd_server()
//{
// int newsockfd = create_accepted_server_socket(BSOCK_TEST_PORT_NUMBER);
// BareosSocket *bs = create_new_bareos_socket(newsockfd);
// storagedaemon::HandleConnectionRequest(bs);
//}
//
//#define DIRECTOR_DAEMON
//#include "include/bareos.h"
//#include "console/console_conf.h"
//#include "lib/tls_openssl.h"
//
//#include "include/jcr.h"
//#include "dird/sd_cmds.h"
//#include "dird/dird_globals.h"
//#include "dird/dird_conf.h"
//
//#include <thread>
//
//static void connect_dir_to_sd()
//{
// JobControlRecord jcr;
// directordaemon::ConnectToStorageDaemon(&jcr, 10, 1, true);
//}
//#undef DIRECTOR_DAEMON
//
//TEST(bsock_dir_sd, dir_to_sd_connection_test)
//{
// std::thread server_thread(start_sd_server);
// connect_dir_to_sd();
// InitForTest();
// std::thread storage_thread(start_sd_server);
// std::thread director_thread(connect_dir_to_sd);
// storage_thread.join();
// director_thread.join();
//}

/* ********************************************************/
Expand Down

0 comments on commit 1d46849

Please sign in to comment.