Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
a60dde2e
Commit
a60dde2e
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
tests: use shutdown
parent
201982b1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/dhtproxytester.cpp
+13
-3
13 additions, 3 deletions
tests/dhtproxytester.cpp
tests/dhtrunnertester.cpp
+22
-14
22 additions, 14 deletions
tests/dhtrunnertester.cpp
with
35 additions
and
17 deletions
tests/dhtproxytester.cpp
+
13
−
3
View file @
a60dde2e
...
...
@@ -60,9 +60,19 @@ void
DhtProxyTester
::
tearDown
()
{
nodePeer
.
join
();
nodeClient
.
join
();
nodeProxy
->
shutdown
();
bool
done
=
false
;
std
::
condition_variable
cv
;
std
::
mutex
cv_m
;
nodeProxy
->
shutdown
([
&
]{
std
::
lock_guard
<
std
::
mutex
>
lk
(
cv_m
);
done
=
true
;
cv
.
notify_all
();
});
std
::
unique_lock
<
std
::
mutex
>
lk
(
cv_m
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
5s
,
[
&
]{
return
done
;
}));
serverProxy
.
reset
();
nodeProxy
->
join
();
nodeProxy
.
reset
();
}
void
...
...
@@ -77,12 +87,12 @@ DhtProxyTester::testGetPut() {
dht
::
Value
val
{
"Hey! It's been a long time. How have you been?"
};
auto
val_data
=
val
.
data
;
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
cv_m
);
nodePeer
.
put
(
key
,
std
::
move
(
val
),
[
&
](
bool
)
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
cv_m
);
done
=
true
;
cv
.
notify_all
();
});
std
::
unique_lock
<
std
::
mutex
>
lk
(
cv_m
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
10s
,
[
&
]{
return
done
;
}));
}
...
...
This diff is collapsed.
Click to expand it.
tests/dhtrunnertester.cpp
+
22
−
14
View file @
a60dde2e
...
...
@@ -22,19 +22,32 @@
#include
<chrono>
#include
<mutex>
#include
<condition_variable>
using
namespace
std
::
chrono_literals
;
namespace
test
{
CPPUNIT_TEST_SUITE_REGISTRATION
(
DhtRunnerTester
);
void
DhtRunnerTester
::
setUp
()
{
node1
.
run
(
42222
,
{},
true
);
node2
.
run
(
42232
,
{},
true
);
node1
.
run
(
42222
);
node2
.
run
(
42232
);
node2
.
bootstrap
(
node1
.
getBound
());
}
void
DhtRunnerTester
::
tearDown
()
{
unsigned
done
{
0
};
std
::
condition_variable
cv
;
std
::
mutex
cv_m
;
auto
shutdown
=
[
&
]{
std
::
lock_guard
<
std
::
mutex
>
lk
(
cv_m
);
done
++
;
cv
.
notify_all
();
};
node1
.
shutdown
(
shutdown
);
node2
.
shutdown
(
shutdown
);
std
::
unique_lock
<
std
::
mutex
>
lk
(
cv_m
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
5s
,
[
&
]{
return
done
==
2
;
}));
node1
.
join
();
node2
.
join
();
}
...
...
@@ -90,27 +103,22 @@ DhtRunnerTester::testListen() {
for
(
unsigned
i
=
0
;
i
<
N
;
i
++
)
{
node2
.
put
(
a
,
dht
::
Value
(
"v1"
),
[
&
](
bool
ok
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex
);
putCount
++
;
if
(
ok
)
putOkCount
++
;
}
cv
.
notify_all
();
});
node2
.
put
(
b
,
dht
::
Value
(
"v2"
),
[
&
](
bool
ok
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex
);
putCount
++
;
if
(
ok
)
putOkCount
++
;
}
cv
.
notify_all
();
});
}
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutex
);
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
30
),
[
&
]{
return
putCount
==
N
*
2u
;
});
CPPUNIT_ASSERT_EQUAL
(
N
*
2u
,
putCount
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
30s
,
[
&
]{
return
putCount
==
N
*
2u
;
}));
CPPUNIT_ASSERT_EQUAL
(
N
*
2u
,
putOkCount
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment