Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
parity
Mirrored projects
polkadot-sdk
Commits
b5e221f7
Commit
b5e221f7
authored
5 years ago
by
Fedor Sakharov
Committed by
Gavin Wood
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixes a flaky test (#675)
* Fixes a flaky test * Renames a var * Do not unit the errors in tests
parent
7ac8fdaf
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
polkadot/availability-store/src/worker.rs
+32
-6
32 additions, 6 deletions
polkadot/availability-store/src/worker.rs
with
32 additions
and
6 deletions
polkadot/availability-store/src/worker.rs
+
32
−
6
View file @
b5e221f7
...
...
@@ -794,13 +794,19 @@ mod tests {
use
super
::
*
;
use
std
::
time
::
Duration
;
use
futures
::{
stream
,
channel
::
mpsc
,
Stream
};
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::
sync
::{
Arc
,
Mutex
,
Condvar
};
use
std
::
pin
::
Pin
;
use
tokio
::
runtime
::
Runtime
;
// Just contains topic->channel mapping to give to outer code on `gossip_messages_for` calls.
struct
TestGossipMessages
{
messages
:
Arc
<
Mutex
<
HashMap
<
Hash
,
mpsc
::
UnboundedReceiver
<
(
Hash
,
Hash
,
ErasureChunk
)
>>>>
,
messages
:
Arc
<
Mutex
<
HashMap
<
Hash
,
(
Arc
<
(
Mutex
<
bool
>
,
Condvar
)
>
,
mpsc
::
UnboundedReceiver
<
(
Hash
,
Hash
,
ErasureChunk
)
>
,
),
>>>
,
}
impl
ProvideGossipMessages
for
TestGossipMessages
{
...
...
@@ -808,7 +814,13 @@ mod tests {
->
Pin
<
Box
<
dyn
Stream
<
Item
=
(
Hash
,
Hash
,
ErasureChunk
)
>
+
Send
>>
{
match
self
.messages
.lock
()
.unwrap
()
.remove
(
&
topic
)
{
Some
(
receiver
)
=>
receiver
.boxed
(),
Some
((
pair
,
receiver
))
=>
{
let
(
lock
,
cvar
)
=
&*
pair
;
let
mut
consumed
=
lock
.lock
()
.unwrap
();
*
consumed
=
true
;
cvar
.notify_one
();
receiver
.boxed
()
},
None
=>
stream
::
iter
(
vec!
[])
.boxed
(),
}
}
...
...
@@ -851,9 +863,10 @@ mod tests {
let
topic
=
erasure_coding_topic
(
relay_parent
,
erasure_root
,
local_id
);
let
pair
=
Arc
::
new
((
Mutex
::
new
(
false
),
Condvar
::
new
()));
let
messages
=
TestGossipMessages
{
messages
:
Arc
::
new
(
Mutex
::
new
(
vec!
[
(
topic
,
gossip_receiver
)
(
topic
,
(
pair
.clone
(),
gossip_receiver
)
)
]
.into_iter
()
.collect
()))
};
...
...
@@ -961,11 +974,14 @@ mod tests {
let
topic_1
=
erasure_coding_topic
(
relay_parent
,
erasure_root_1
,
local_id
);
let
topic_2
=
erasure_coding_topic
(
relay_parent
,
erasure_root_2
,
local_id
);
let
cvar_pair1
=
Arc
::
new
((
Mutex
::
new
(
false
),
Condvar
::
new
()));
let
cvar_pair2
=
Arc
::
new
((
Mutex
::
new
(
false
),
Condvar
::
new
()));
let
messages
=
TestGossipMessages
{
messages
:
Arc
::
new
(
Mutex
::
new
(
vec!
[
(
topic_1
,
gossip_receiver_1
),
(
topic_2
,
gossip_receiver_2
),
(
topic_1
,
(
cvar_pair1
.clone
(),
gossip_receiver_1
)
)
,
(
topic_2
,
(
cvar_pair2
,
gossip_receiver_2
)
)
,
]
.into_iter
()
.collect
()))
};
...
...
@@ -1000,6 +1016,16 @@ mod tests {
handle
.sender
.unbounded_send
(
listen_msg_1
)
.unwrap
();
runtime
.block_on
(
r1
)
.unwrap
()
.unwrap
();
// Here, we are racing against the worker thread that might have not yet
// reached the point when it requests the gossip messages for `topic_2`
// which will get them removed from `TestGossipMessages`. Therefore, the
// `Condvar` is used to wait for that event.
let
(
lock
,
cvar1
)
=
&*
cvar_pair1
;
let
mut
gossip_stream_consumed
=
lock
.lock
()
.unwrap
();
while
!*
gossip_stream_consumed
{
gossip_stream_consumed
=
cvar1
.wait
(
gossip_stream_consumed
)
.unwrap
();
}
// The gossip sender taken => listener registered.
assert!
(
!
messages
.messages
.lock
()
.unwrap
()
.contains_key
(
&
topic_1
));
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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