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
f4c6c54a
You need to sign in or sign up before continuing.
Commit
f4c6c54a
authored
4 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
unit tests: add test for identityAnnouncedCb, putEncrypted
parent
4dc7a5ca
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/dhtrunnertester.cpp
+71
-0
71 additions, 0 deletions
tests/dhtrunnertester.cpp
tests/dhtrunnertester.h
+5
-0
5 additions, 0 deletions
tests/dhtrunnertester.h
with
76 additions
and
0 deletions
tests/dhtrunnertester.cpp
+
71
−
0
View file @
f4c6c54a
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include
<mutex>
#include
<mutex>
#include
<condition_variable>
#include
<condition_variable>
using
namespace
std
::
chrono_literals
;
using
namespace
std
::
chrono_literals
;
using
namespace
std
::
literals
;
namespace
test
{
namespace
test
{
CPPUNIT_TEST_SUITE_REGISTRATION
(
DhtRunnerTester
);
CPPUNIT_TEST_SUITE_REGISTRATION
(
DhtRunnerTester
);
...
@@ -173,6 +174,76 @@ DhtRunnerTester::testListen() {
...
@@ -173,6 +174,76 @@ DhtRunnerTester::testListen() {
node1
.
cancelListen
(
d
,
tokend
);
node1
.
cancelListen
(
d
,
tokend
);
}
}
void
DhtRunnerTester
::
testIdOps
()
{
std
::
mutex
mutex
;
std
::
condition_variable
cv
;
unsigned
valueCount
(
0
);
dht
::
DhtRunner
::
Config
config2
;
config2
.
dht_config
.
node_config
.
max_peer_req_per_sec
=
-
1
;
config2
.
dht_config
.
node_config
.
max_req_per_sec
=
-
1
;
config2
.
dht_config
.
id
=
dht
::
crypto
::
generateIdentity
();
dht
::
DhtRunner
::
Context
context2
;
context2
.
identityAnnouncedCb
=
[
&
](
bool
ok
)
{
CPPUNIT_ASSERT
(
ok
);
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex
);
valueCount
++
;
cv
.
notify_all
();
};
node2
.
join
();
node2
.
run
(
42232
,
config2
,
std
::
move
(
context2
));
node2
.
bootstrap
(
node1
.
getBound
());
node1
.
findCertificate
(
node2
.
getId
(),
[
&
](
const
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>&
crt
){
CPPUNIT_ASSERT
(
crt
);
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex
);
valueCount
++
;
cv
.
notify_all
();
});
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutex
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
20s
,
[
&
]{
return
valueCount
==
2
;
}));
}
dht
::
DhtRunner
::
Context
context1
;
context1
.
identityAnnouncedCb
=
[
&
](
bool
ok
)
{
CPPUNIT_ASSERT
(
ok
);
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex
);
valueCount
++
;
cv
.
notify_all
();
};
config2
.
dht_config
.
id
=
dht
::
crypto
::
generateIdentity
();
node1
.
join
();
node1
.
run
(
42222
,
config2
,
std
::
move
(
context1
));
node1
.
bootstrap
(
node2
.
getBound
());
auto
key
=
dht
::
InfoHash
::
get
(
"key"
);
node1
.
putEncrypted
(
key
,
node2
.
getId
(),
dht
::
Value
(
"yo"
),
[
&
](
bool
ok
){
CPPUNIT_ASSERT
(
ok
);
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex
);
valueCount
++
;
cv
.
notify_all
();
});
node2
.
listen
<
std
::
string
>
(
key
,
[
&
](
std
::
string
&&
value
){
CPPUNIT_ASSERT_EQUAL
(
"yo"
s
,
value
);
std
::
lock_guard
<
std
::
mutex
>
lk
(
mutex
);
valueCount
++
;
cv
.
notify_all
();
return
false
;
});
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutex
);
CPPUNIT_ASSERT
(
cv
.
wait_for
(
lk
,
20s
,
[
&
]{
return
valueCount
==
4
;
}));
}
}
void
void
DhtRunnerTester
::
testListenLotOfBytes
()
{
DhtRunnerTester
::
testListenLotOfBytes
()
{
std
::
mutex
mutex
;
std
::
mutex
mutex
;
...
...
This diff is collapsed.
Click to expand it.
tests/dhtrunnertester.h
+
5
−
0
View file @
f4c6c54a
...
@@ -33,6 +33,7 @@ class DhtRunnerTester : public CppUnit::TestFixture {
...
@@ -33,6 +33,7 @@ class DhtRunnerTester : public CppUnit::TestFixture {
CPPUNIT_TEST
(
testGetPut
);
CPPUNIT_TEST
(
testGetPut
);
CPPUNIT_TEST
(
testListen
);
CPPUNIT_TEST
(
testListen
);
CPPUNIT_TEST
(
testListenLotOfBytes
);
CPPUNIT_TEST
(
testListenLotOfBytes
);
CPPUNIT_TEST
(
testIdOps
);
CPPUNIT_TEST_SUITE_END
();
CPPUNIT_TEST_SUITE_END
();
dht
::
DhtRunner
node1
{};
dht
::
DhtRunner
node1
{};
...
@@ -58,6 +59,10 @@ class DhtRunnerTester : public CppUnit::TestFixture {
...
@@ -58,6 +59,10 @@ class DhtRunnerTester : public CppUnit::TestFixture {
* Test listen method
* Test listen method
*/
*/
void
testListen
();
void
testListen
();
/**
* Test methods requiring a node identity
*/
void
testIdOps
();
/**
/**
* Test listen method with lot of datas
* Test listen method with lot of datas
*/
*/
...
...
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