Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Nicolas Pope
ftl
Commits
85d694bd
Commit
85d694bd
authored
5 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Add back more peer tests
parent
80dd8500
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
net/cpp/src/protocol.cpp
+0
-47
0 additions, 47 deletions
net/cpp/src/protocol.cpp
net/cpp/test/peer_unit.cpp
+25
-40
25 additions, 40 deletions
net/cpp/test/peer_unit.cpp
with
25 additions
and
87 deletions
net/cpp/src/protocol.cpp
deleted
100644 → 0
+
0
−
47
View file @
80dd8500
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include
<glog/logging.h>
#include
<ftl/net/socket.hpp>
#include
<ftl/net/protocol.hpp>
#include
<functional>
#include
<iostream>
using
ftl
::
net
::
Socket
;
using
ftl
::
net
::
Protocol
;
std
::
map
<
std
::
string
,
Protocol
*>
Protocol
::
protocols__
;
Protocol
*
Protocol
::
find
(
const
std
::
string
&
id
)
{
if
(
protocols__
.
count
(
id
)
>
0
)
return
protocols__
[
id
];
else
return
NULL
;
}
Protocol
::
Protocol
(
const
std
::
string
&
id
)
:
id_
(
id
)
{
protocols__
[
id
]
=
this
;
}
Protocol
::~
Protocol
()
{
protocols__
.
erase
(
id_
);
// TODO Make sure all dependent sockets are closed!
}
void
Protocol
::
bind
(
int
service
,
std
::
function
<
void
(
uint32_t
,
Socket
&
)
>
func
)
{
if
(
handlers_
.
count
(
service
)
==
0
)
{
handlers_
[
service
]
=
func
;
}
else
{
LOG
(
ERROR
)
<<
"Message service "
<<
service
<<
" already bound"
;
}
}
void
Protocol
::
dispatchRPC
(
Socket
&
s
,
const
std
::
string
&
d
)
{
disp_
.
dispatch
(
s
,
d
);
}
void
Protocol
::
dispatchRaw
(
uint32_t
service
,
Socket
&
s
)
{
// Lookup raw message handler
if
(
handlers_
.
count
(
service
)
>
0
)
{
handlers_
[
service
](
service
,
s
);
}
else
{
LOG
(
ERROR
)
<<
"Unrecognised service request ("
<<
service
<<
") from "
<<
s
.
getURI
();
}
}
This diff is collapsed.
Click to expand it.
net/cpp/test/peer_unit.cpp
+
25
−
40
View file @
85d694bd
...
@@ -260,26 +260,6 @@ TEST_CASE("Peer::bind()", "[rpc]") {
...
@@ -260,26 +260,6 @@ TEST_CASE("Peer::bind()", "[rpc]") {
}
}
}
}
/*TEST_CASE("Socket::operator>>()", "[io]") {
MockPeer s;
SECTION("stream ints") {
int i[2];
i[0] = 99;
i[1] = 101;
fake_send(0, 100, std::string((char*)&i,2*sizeof(int)));
i[0] = 0;
i[1] = 0;
s.mock_data(); // Force a message read, but no protocol...
REQUIRE( (s.size() == 2*sizeof(int)) );
s >> i;
REQUIRE( (i[0] == 99) );
REQUIRE( (i[1] == 101) );
}
}*/
TEST_CASE
(
"Socket::send()"
,
"[io]"
)
{
TEST_CASE
(
"Socket::send()"
,
"[io]"
)
{
MockPeer
s
;
MockPeer
s
;
...
@@ -293,49 +273,54 @@ TEST_CASE("Socket::send()", "[io]") {
...
@@ -293,49 +273,54 @@ TEST_CASE("Socket::send()", "[io]") {
REQUIRE
(
(
get
<
0
>
(
value
)
==
607
)
);
REQUIRE
(
(
get
<
0
>
(
value
)
==
607
)
);
}
}
/*
SECTION("send a string") {
SECTION
(
"send a string"
)
{
std
::
string
str
(
"hello world"
);
std
::
string
str
(
"hello world"
);
s.send(
100
,str);
s
.
send
(
"dummy"
,
str
);
REQUIRE( (get_service(0) == 100) );
auto
[
name
,
value
]
=
readResponse
<
tuple
<
std
::
string
>>
(
0
);
REQUIRE( (get_size(0) == str.size()) );
REQUIRE( (get_value<std::string>(0) == "hello world") );
REQUIRE
(
(
name
==
"dummy"
)
);
REQUIRE
(
(
get
<
0
>
(
value
)
==
"hello world"
)
);
}
}
SECTION
(
"send const char* string"
)
{
SECTION
(
"send const char* string"
)
{
s.send(
100
,"hello world");
s
.
send
(
"dummy"
,
"hello world"
);
REQUIRE( (get_service(0) == 100) );
auto
[
name
,
value
]
=
readResponse
<
tuple
<
std
::
string
>>
(
0
);
REQUIRE( (get_size(0) == 11) );
REQUIRE( (get_value<std::string>(0) == "hello world") );
REQUIRE
(
(
name
==
"dummy"
)
);
REQUIRE
(
(
get
<
0
>
(
value
)
==
"hello world"
)
);
}
}
SECTION("send const char* array") {
/*
SECTION("send const char* array") {
s.send(100,ftl::net::array{"hello world",10});
s.send(100,ftl::net::array{"hello world",10});
REQUIRE( (get_service(0) == 100) );
REQUIRE( (get_service(0) == 100) );
REQUIRE( (get_size(0) == 10) );
REQUIRE( (get_size(0) == 10) );
REQUIRE( (get_value<std::string>(0) == "hello worl") );
REQUIRE( (get_value<std::string>(0) == "hello worl") );
}
}
*/
SECTION
(
"send a tuple"
)
{
SECTION
(
"send a tuple"
)
{
auto
tup
=
std
::
make_tuple
(
55
,
66
,
true
,
6.7
);
auto
tup
=
std
::
make_tuple
(
55
,
66
,
true
,
6.7
);
s.send(
100
,tup);
s
.
send
(
"dummy"
,
tup
);
REQUIRE( (get_service(0) == 100) );
auto
[
name
,
value
]
=
readResponse
<
tuple
<
decltype
(
tup
)
>>
(
0
);
REQUIRE( (get_size(0) == sizeof(tup)) );
REQUIRE( (get_value<decltype(tup)>(0) == tup) );
REQUIRE
(
(
name
==
"dummy"
)
);
REQUIRE
(
(
get
<
1
>
(
get
<
0
>
(
value
))
==
66
)
);
}
}
SECTION
(
"send multiple strings"
)
{
SECTION
(
"send multiple strings"
)
{
std
::
string
str
(
"hello "
);
std
::
string
str
(
"hello "
);
std
::
string
str2
(
"world"
);
std
::
string
str2
(
"world"
);
s.send(
100
,str,str2);
s
.
send
(
"dummy2"
,
str
,
str2
);
REQUIRE( (get_service(0) == 100) );
auto
[
name
,
value
]
=
readResponse
<
tuple
<
std
::
string
,
std
::
string
>>
(
0
);
REQUIRE( (get_size(0) == str.size()+str2.size()) );
REQUIRE( (get_value<std::string>(0) == "hello world") );
REQUIRE
(
(
name
==
"dummy2"
)
);
}*/
REQUIRE
(
(
get
<
0
>
(
value
)
==
"hello"
)
);
REQUIRE
(
(
get
<
1
>
(
value
)
==
"world"
)
);
}
}
}
/*TEST_CASE("Socket::read()", "[io]") {
/*TEST_CASE("Socket::read()", "[io]") {
...
...
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