Workaround for initializing folly inside gtests
This commit is contained in:
parent
79ffcc1793
commit
3b1d1449be
22
tests/unit/coward_the_cowardly_dog.h
Normal file
22
tests/unit/coward_the_cowardly_dog.h
Normal 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; }
|
||||
};
|
@ -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();
|
||||
|
@ -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>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user