Skip to content

Commit

Permalink
Remove sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
heng committed Jul 18, 2019
1 parent b3f8684 commit 2654bc2
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/kvstore/raftex/RaftPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class RaftPart : public std::enable_shared_from_this<RaftPart> {
void addLearner(const HostAddr& learner);

// Change the partition status to RUNNING. This is called
// by the inherited class, when it's ready to server
// by the inherited class, when it's ready to serve
virtual void start(std::vector<HostAddr>&& peers, bool asLearner = false);

// Change the partition status to STOPPED. This is called
Expand Down
2 changes: 1 addition & 1 deletion src/kvstore/raftex/test/LearnerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018 vesoft inc. All rights reserved.
/* Copyright (c) 2019 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
Expand Down
4 changes: 1 addition & 3 deletions src/kvstore/raftex/test/RaftexTestBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void waitUntilLeaderElected(
});

// Sleep some time to wait until resp of heartbeat has come back when elected as leader
usleep(10000);
usleep(30000);

bool sameLeader = true;
int32_t index = 0;
Expand All @@ -121,8 +121,6 @@ void waitUntilLeaderElected(
// Wait for one second
sleep(1);
}
// Wait for 50ms for the hb
usleep(50000);
}


Expand Down
7 changes: 4 additions & 3 deletions src/kvstore/test/NebulaStoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ TEST(NebulaStoreTest, SimpleTest) {
sizeof(int32_t)),
folly::stringPrintf("val_%d", i));
}
store->asyncMultiPut(1, 1, std::move(data), [](ResultCode code){
folly::Baton<true, std::atomic> baton;
store->asyncMultiPut(1, 1, std::move(data), [&] (ResultCode code){
EXPECT_EQ(ResultCode::SUCCEEDED, code);
baton.post();
});

sleep(1);
baton.wait();
int32_t start = 0;
int32_t end = 100;
std::string s(reinterpret_cast<const char*>(&start), sizeof(int32_t));
Expand Down
19 changes: 12 additions & 7 deletions src/meta/test/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "meta/processors/partsMan/ListHostsProcessor.h"
#include "meta/MetaServiceHandler.h"
#include <thrift/lib/cpp2/server/ThriftServer.h>
#include <folly/synchronization/Baton.h>
#include "meta/processors/usersMan/AuthenticationProcessor.h"
#include "interface/gen-cpp2/common_types.h"
#include "time/WallClock.h"
Expand Down Expand Up @@ -117,12 +118,13 @@ class TestUtils {
data.emplace_back(MetaServiceUtils::partKey(id, partId),
MetaServiceUtils::partVal(hosts));
}

folly::Baton<true, std::atomic> baton;
kv->asyncMultiPut(0, 0, std::move(data),
[&] (kvstore::ResultCode code) {
ret = (code == kvstore::ResultCode::SUCCEEDED);
baton.post();
});
usleep(10000);
baton.wait();
return ret;
}

Expand All @@ -144,12 +146,13 @@ class TestUtils {
tags.emplace_back(MetaServiceUtils::schemaTagKey(1, tagId, ver++),
MetaServiceUtils::schemaTagVal(tagName, srcsch));
}

folly::Baton<true, std::atomic> baton;
kv->asyncMultiPut(0, 0, std::move(tags),
[] (kvstore::ResultCode code) {
[&] (kvstore::ResultCode code) {
ASSERT_EQ(kvstore::ResultCode::SUCCEEDED, code);
baton.post();
});
usleep(10000);
baton.wait();
}

static void mockEdge(kvstore::KVStore* kv, int32_t edgeNum, SchemaVer version = 0) {
Expand All @@ -172,10 +175,12 @@ class TestUtils {
MetaServiceUtils::schemaEdgeVal(edgeName, srcsch));
}

kv->asyncMultiPut(0, 0, std::move(edges), [] (kvstore::ResultCode code) {
folly::Baton<true, std::atomic> baton;
kv->asyncMultiPut(0, 0, std::move(edges), [&] (kvstore::ResultCode code) {
ASSERT_EQ(kvstore::ResultCode::SUCCEEDED, code);
baton.post();
});
usleep(10000);
baton.wait();
}

static std::unique_ptr<test::ServerContext> mockMetaServer(uint16_t port,
Expand Down
4 changes: 3 additions & 1 deletion src/storage/test/QueryBoundTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ void mockData(kvstore::KVStore* kv) {
}
}
}
folly::Baton<true, std::atomic> baton;
kv->asyncMultiPut(
0, partId, std::move(data),
[&](kvstore::ResultCode code) {
EXPECT_EQ(code, kvstore::ResultCode::SUCCEEDED);
baton.post();
});
baton.wait();
}
sleep(1);
}


Expand Down
4 changes: 3 additions & 1 deletion src/storage/test/QueryEdgePropsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ void mockData(kvstore::KVStore* kv) {
data.emplace_back(std::move(key), std::move(val));
}
}
folly::Baton<true, std::atomic> baton;
kv->asyncMultiPut(
0, partId, std::move(data),
[&](kvstore::ResultCode code) {
EXPECT_EQ(code, kvstore::ResultCode::SUCCEEDED);
baton.post();
});
baton.wait();
}
sleep(1);
}


Expand Down
4 changes: 3 additions & 1 deletion src/storage/test/QueryStatsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ void mockData(kvstore::KVStore* kv) {
data.emplace_back(std::move(key), std::move(val));
}
}
folly::Baton<true, std::atomic> baton;
kv->asyncMultiPut(0, partId, std::move(data), [&](kvstore::ResultCode code) {
EXPECT_EQ(code, kvstore::ResultCode::SUCCEEDED);
baton.post();
});
baton.wait();
}
sleep(1);
}


Expand Down
5 changes: 3 additions & 2 deletions src/storage/test/QueryVertexPropsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ TEST(QueryVertexPropsTest, SimpleTest) {
data.emplace_back(std::move(key), std::move(val));
}
}
folly::Baton<true, std::atomic> baton;
kv->asyncMultiPut(
0,
partId,
std::move(data),
[&](kvstore::ResultCode code) {
EXPECT_EQ(code, kvstore::ResultCode::SUCCEEDED);
baton.post();
});
baton.wait();
}

sleep(1);
LOG(INFO) << "Build VertexPropsRequest...";
cpp2::VertexPropRequest req;
req.set_space_id(0);
Expand Down
1 change: 1 addition & 0 deletions src/storage/test/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "dataman/ResultSchemaProvider.h"
#include "storage/StorageServiceHandler.h"
#include <thrift/lib/cpp2/server/ThriftServer.h>
#include <folly/synchronization/Baton.h>
#include "meta/SchemaManager.h"
#include <folly/executors/ThreadPoolExecutor.h>
#include <folly/executors/CPUThreadPoolExecutor.h>
Expand Down

0 comments on commit 2654bc2

Please sign in to comment.