Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
folly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
folly
Commits
f1bd6185
Commit
f1bd6185
authored
Oct 16, 2018
by
Kirk Shoop
Committed by
Facebook Github Bot
Oct 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add missing tests
fbshipit-source-id: 30a9f3571fb0a26d0023e3596105d2a38cf2d5e1
parent
4309d2bb
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
694 additions
and
1 deletion
+694
-1
folly/experimental/pushmi/.gitignore
folly/experimental/pushmi/.gitignore
+34
-0
folly/experimental/pushmi/test/CMakeLists.txt
folly/experimental/pushmi/test/CMakeLists.txt
+1
-1
folly/experimental/pushmi/test/CompileTest.cpp
folly/experimental/pushmi/test/CompileTest.cpp
+318
-0
folly/experimental/pushmi/test/NewThreadTest.cpp
folly/experimental/pushmi/test/NewThreadTest.cpp
+173
-0
folly/experimental/pushmi/test/TrampolineTest.cpp
folly/experimental/pushmi/test/TrampolineTest.cpp
+168
-0
No files found.
folly/experimental/pushmi/.gitignore
0 → 100644
View file @
f1bd6185
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
build/**
\ No newline at end of file
folly/experimental/pushmi/test/CMakeLists.txt
View file @
f1bd6185
add_executable
(
PushmiTest catch.cpp PushmiTest.cpp
)
add_executable
(
PushmiTest catch.cpp
CompileTest.cpp NewThreadTest.cpp TrampolineTest.cpp
PushmiTest.cpp
)
target_link_libraries
(
PushmiTest
pushmi
Threads::Threads
)
folly/experimental/pushmi/test/CompileTest.cpp
0 → 100644
View file @
f1bd6185
This diff is collapsed.
Click to expand it.
folly/experimental/pushmi/test/NewThreadTest.cpp
0 → 100644
View file @
f1bd6185
#include "catch.hpp"
#include <type_traits>
#include <chrono>
using
namespace
std
::
literals
;
#include "pushmi/flow_single_deferred.h"
#include "pushmi/o/empty.h"
#include "pushmi/o/just.h"
#include "pushmi/o/on.h"
#include "pushmi/o/transform.h"
#include "pushmi/o/tap.h"
#include "pushmi/o/via.h"
#include "pushmi/o/submit.h"
#include "pushmi/o/extension_operators.h"
#include "pushmi/trampoline.h"
#include "pushmi/new_thread.h"
using
namespace
pushmi
::
aliases
;
struct
countdownsingle
{
countdownsingle
(
int
&
c
)
:
counter
(
&
c
)
{}
int
*
counter
;
template
<
class
ExecutorRef
>
void
operator
()(
ExecutorRef
exec
)
{
if
(
--*
counter
>
0
)
{
exec
|
op
::
submit
(
*
this
);
}
}
};
SCENARIO
(
"new_thread executor"
,
"[new_thread][deferred]"
)
{
GIVEN
(
"A new_thread time_single_deferred"
)
{
auto
nt
=
v
::
new_thread
();
using
NT
=
decltype
(
nt
);
// REQUIRE( v::TimeSingleDeferred<
// NT, v::archetype_single,
// NT&, std::exception_ptr> );
// REQUIRE( v::TimeExecutor<
// NT&, v::archetype_single,
// std::exception_ptr> );
auto
any
=
v
::
any_time_executor
{
nt
};
WHEN
(
"blocking submit now"
)
{
auto
signals
=
0
;
auto
start
=
v
::
now
(
nt
);
auto
signaled
=
v
::
now
(
nt
);
nt
|
op
::
transform
([](
auto
nt
){
return
nt
|
ep
::
now
();
})
|
op
::
blocking_submit
(
[
&
](
auto
at
){
signaled
=
at
;
signals
+=
100
;
},
[
&
](
auto
e
)
noexcept
{
signals
+=
1000
;
},
[
&
](){
signals
+=
10
;
});
THEN
(
"the value signal is recorded once and the signal did not drift much"
)
{
REQUIRE
(
signals
==
100
);
INFO
(
"The delay is "
<<
::
Catch
::
Detail
::
stringify
(
signaled
-
start
));
REQUIRE
(
signaled
-
start
<
10s
);
}
}
WHEN
(
"blocking get now"
)
{
auto
start
=
v
::
now
(
nt
);
auto
signaled
=
nt
|
op
::
transform
([](
auto
nt
){
return
v
::
now
(
nt
);
})
|
op
::
get
<
std
::
chrono
::
system_clock
::
time_point
>
;
THEN
(
"the signal did not drift much"
)
{
INFO
(
"The delay is "
<<
::
Catch
::
Detail
::
stringify
(
signaled
-
start
));
REQUIRE
(
signaled
-
start
<
10s
);
}
}
WHEN
(
"submissions are ordered in time"
)
{
std
::
vector
<
std
::
string
>
times
;
auto
push
=
[
&
](
int
time
)
{
return
v
::
on_value
([
&
,
time
](
auto
)
{
times
.
push_back
(
std
::
to_string
(
time
));
});
};
nt
|
op
::
blocking_submit
(
v
::
on_value
{[
push
](
auto
nt
)
{
nt
|
op
::
submit_after
(
40ms
,
push
(
40
))
|
op
::
submit_after
(
10ms
,
push
(
10
))
|
op
::
submit_after
(
20ms
,
push
(
20
))
|
op
::
submit_after
(
10ms
,
push
(
11
));
}});
THEN
(
"the items were pushed in time order not insertion order"
)
{
REQUIRE
(
times
==
std
::
vector
<
std
::
string
>
{
"10"
,
"11"
,
"20"
,
"40"
});
}
}
WHEN
(
"now is called"
)
{
bool
done
=
false
;
nt
|
ep
::
now
();
nt
|
op
::
blocking_submit
([
&
](
auto
nt
)
{
nt
|
ep
::
now
();
done
=
true
;
});
THEN
(
"both calls to now() complete"
)
{
REQUIRE
(
done
==
true
);
}
}
WHEN
(
"virtual derecursion is triggered"
)
{
int
counter
=
100'000
;
std
::
function
<
void
(
pushmi
::
archtype_any_time_executor_ref
exec
)
>
recurse
;
recurse
=
[
&
](
pushmi
::
archtype_any_time_executor_ref
nt
)
{
if
(
--
counter
<=
0
)
return
;
nt
|
op
::
submit
(
recurse
);
};
nt
|
op
::
blocking_submit
([
&
](
auto
nt
)
{
recurse
(
nt
);
});
THEN
(
"all nested submissions complete"
)
{
REQUIRE
(
counter
==
0
);
}
}
WHEN
(
"static derecursion is triggered"
)
{
int
counter
=
100'000
;
countdownsingle
single
{
counter
};
nt
|
op
::
blocking_submit
(
single
);
THEN
(
"all nested submissions complete"
)
{
REQUIRE
(
counter
==
0
);
}
}
WHEN
(
"used with on"
)
{
std
::
vector
<
std
::
string
>
values
;
auto
deferred
=
pushmi
::
single_deferred
([](
auto
out
)
{
::
pushmi
::
set_value
(
out
,
2.0
);
// ignored
::
pushmi
::
set_value
(
out
,
1
);
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
min
());
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
max
());
});
deferred
|
op
::
on
([
&
](){
return
nt
;})
|
op
::
blocking_submit
(
v
::
on_value
{[
&
](
auto
v
)
{
values
.
push_back
(
std
::
to_string
(
v
));
}});
THEN
(
"only the first item was pushed"
)
{
REQUIRE
(
values
==
std
::
vector
<
std
::
string
>
{
"2.000000"
});
}
}
WHEN
(
"used with via"
)
{
std
::
vector
<
std
::
string
>
values
;
auto
deferred
=
pushmi
::
single_deferred
([](
auto
out
)
{
::
pushmi
::
set_value
(
out
,
2.0
);
// ignored
::
pushmi
::
set_value
(
out
,
1
);
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
min
());
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
max
());
});
deferred
|
op
::
via
([
&
](){
return
nt
;})
|
op
::
blocking_submit
(
v
::
on_value
{[
&
](
auto
v
)
{
values
.
push_back
(
std
::
to_string
(
v
));
}});
THEN
(
"only the first item was pushed"
)
{
REQUIRE
(
values
==
std
::
vector
<
std
::
string
>
{
"2.000000"
});
}
}
}
}
folly/experimental/pushmi/test/TrampolineTest.cpp
0 → 100644
View file @
f1bd6185
#include "catch.hpp"
#include <type_traits>
#include <chrono>
using
namespace
std
::
literals
;
#include "pushmi/flow_single_deferred.h"
#include "pushmi/o/empty.h"
#include "pushmi/o/just.h"
#include "pushmi/o/on.h"
#include "pushmi/o/transform.h"
#include "pushmi/o/tap.h"
#include "pushmi/o/via.h"
#include "pushmi/o/submit.h"
#include "pushmi/o/extension_operators.h"
#include "pushmi/trampoline.h"
#include "pushmi/new_thread.h"
using
namespace
pushmi
::
aliases
;
struct
countdownsingle
{
countdownsingle
(
int
&
c
)
:
counter
(
&
c
)
{}
int
*
counter
;
template
<
class
ExecutorRef
>
void
operator
()(
ExecutorRef
exec
)
{
if
(
--*
counter
>
0
)
{
exec
|
op
::
submit
(
*
this
);
}
}
};
SCENARIO
(
"trampoline executor"
,
"[trampoline][deferred]"
)
{
GIVEN
(
"A trampoline time_single_deferred"
)
{
auto
tr
=
v
::
trampoline
();
using
TR
=
decltype
(
tr
);
// REQUIRE( v::TimeSingleDeferred<
// TR, v::archetype_single,
// TR&, std::exception_ptr> );
// REQUIRE( v::TimeExecutor<
// TR&, v::archetype_single,
// std::exception_ptr> );
WHEN
(
"submit now"
)
{
auto
signals
=
0
;
auto
start
=
v
::
now
(
tr
);
auto
signaled
=
v
::
now
(
tr
);
tr
|
op
::
transform
([](
auto
tr
){
return
v
::
now
(
tr
);
})
|
op
::
submit
(
[
&
](
auto
at
){
signaled
=
at
;
signals
+=
100
;
},
[
&
](
auto
e
)
noexcept
{
signals
+=
1000
;
},
[
&
](){
signals
+=
10
;
});
THEN
(
"the value signal is recorded once and the signal did not drift much"
)
{
REQUIRE
(
signals
==
100
);
INFO
(
"The delay is "
<<
::
Catch
::
Detail
::
stringify
(
signaled
-
start
));
REQUIRE
(
signaled
-
start
<
10s
);
}
}
WHEN
(
"blocking get now"
)
{
auto
start
=
v
::
now
(
tr
);
auto
signaled
=
tr
|
op
::
transform
([](
auto
tr
){
return
v
::
now
(
tr
);
})
|
op
::
get
<
decltype
(
v
::
now
(
tr
))
>
;
THEN
(
"the signal did not drift much"
)
{
INFO
(
"The delay is "
<<
::
Catch
::
Detail
::
stringify
(
signaled
-
start
));
REQUIRE
(
signaled
-
start
<
10s
);
}
}
WHEN
(
"submissions are ordered in time"
)
{
std
::
vector
<
std
::
string
>
times
;
auto
push
=
[
&
](
int
time
)
{
return
v
::
on_value
([
&
,
time
](
auto
)
{
times
.
push_back
(
std
::
to_string
(
time
));
});
};
tr
|
op
::
submit
(
v
::
on_value
{[
push
](
auto
tr
)
{
tr
|
op
::
submit_after
(
40ms
,
push
(
40
))
|
op
::
submit_after
(
10ms
,
push
(
10
))
|
op
::
submit_after
(
20ms
,
push
(
20
))
|
op
::
submit_after
(
10ms
,
push
(
11
));
}});
THEN
(
"the items were pushed in time order not insertion order"
)
{
REQUIRE
(
times
==
std
::
vector
<
std
::
string
>
{
"10"
,
"11"
,
"20"
,
"40"
});
}
}
WHEN
(
"now is called"
)
{
bool
done
=
false
;
tr
|
ep
::
now
();
tr
|
op
::
submit
([
&
](
auto
tr
)
{
tr
|
ep
::
now
();
done
=
true
;
});
THEN
(
"both calls to now() complete"
)
{
REQUIRE
(
done
==
true
);
}
}
WHEN
(
"virtual derecursion is triggered"
)
{
int
counter
=
100'000
;
std
::
function
<
void
(
pushmi
::
archtype_any_time_executor_ref
exec
)
>
recurse
;
recurse
=
[
&
](
pushmi
::
archtype_any_time_executor_ref
tr
)
{
if
(
--
counter
<=
0
)
return
;
tr
|
op
::
submit
(
recurse
);
};
tr
|
op
::
submit
([
&
](
auto
exec
)
{
recurse
(
exec
);
});
THEN
(
"all nested submissions complete"
)
{
REQUIRE
(
counter
==
0
);
}
}
WHEN
(
"static derecursion is triggered"
)
{
int
counter
=
100'000
;
countdownsingle
single
{
counter
};
tr
|
op
::
submit
(
single
);
THEN
(
"all nested submissions complete"
)
{
REQUIRE
(
counter
==
0
);
}
}
WHEN
(
"used with on"
)
{
std
::
vector
<
std
::
string
>
values
;
auto
deferred
=
pushmi
::
single_deferred
([](
auto
out
)
{
::
pushmi
::
set_value
(
out
,
2.0
);
// ignored
::
pushmi
::
set_value
(
out
,
1
);
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
min
());
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
max
());
});
deferred
|
op
::
on
([
&
](){
return
tr
;})
|
op
::
submit
(
v
::
on_value
{[
&
](
auto
v
)
{
values
.
push_back
(
std
::
to_string
(
v
));
}});
THEN
(
"only the first item was pushed"
)
{
REQUIRE
(
values
==
std
::
vector
<
std
::
string
>
{
"2.000000"
});
}
}
WHEN
(
"used with via"
)
{
std
::
vector
<
std
::
string
>
values
;
auto
deferred
=
pushmi
::
single_deferred
([](
auto
out
)
{
::
pushmi
::
set_value
(
out
,
2.0
);
// ignored
::
pushmi
::
set_value
(
out
,
1
);
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
min
());
::
pushmi
::
set_value
(
out
,
std
::
numeric_limits
<
int8_t
>::
max
());
});
deferred
|
op
::
via
([
&
](){
return
tr
;})
|
op
::
submit
(
v
::
on_value
{[
&
](
auto
v
)
{
values
.
push_back
(
std
::
to_string
(
v
));
}});
THEN
(
"only the first item was pushed"
)
{
REQUIRE
(
values
==
std
::
vector
<
std
::
string
>
{
"2.000000"
});
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment