Workaround for initializing folly inside gtests

This commit is contained in:
gvolfing 2022-08-18 15:59:27 +02:00
parent 79ffcc1793
commit 3b1d1449be
3 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,22 @@
// Copyright 2022 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
#include <string>
#include "gtest/gtest.h"
namespace clahelper {
inline std::string g_command_line_arg;
}
class MyTestEnvironment : public testing::Environment {
public:
explicit MyTestEnvironment(const std::string &command_line_arg) { clahelper::g_command_line_arg = command_line_arg; }
};

View File

@ -12,9 +12,15 @@
#include <gtest/gtest.h>
#include <utils/logging.hpp>
#include "coward_the_cowardly_dog.h"
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
std::string command_line_arg(argv[0]);
testing::InitGoogleTest(&argc, argv);
testing::AddGlobalTestEnvironment(new MyTestEnvironment(command_line_arg));
memgraph::logging::RedirectToStderr();
spdlog::set_level(spdlog::level::trace);
return RUN_ALL_TESTS();

View File

@ -25,6 +25,8 @@
#include "io/thrift/thrift_transport.hpp"
#include "coward_the_cowardly_dog.h"
using namespace memgraph::io;
using namespace apache::thrift;
@ -89,6 +91,12 @@ class EchoSvc : public EchoSvIf {
TEST(ThriftTransport, Echo) {
// TODO(tyler and gabor) use thrift-generated echo, and thrift transport, to send, reply, and receive the response for
// a thrift-defined message
int argc = 1;
const char *arg2 = clahelper::g_command_line_arg.c_str();
char *arg = const_cast<char *>(arg2);
char **argv = &arg;
folly::Init(&argc, &argv);
auto ptr1 = std::make_shared<EchoSvc>();
auto ptr2 = std::make_shared<EchoSvc>();