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 a2842c2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
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
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 a2842c2

Please sign in to comment.