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
5d5cc9a0
Commit
5d5cc9a0
authored
2 years ago
by
Bastian Köcher
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
sp-runtime-interface-test: Fix flaky test (#13770)
parent
95da8d7a
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/primitives/runtime-interface/test/src/lib.rs
+64
-41
64 additions, 41 deletions
substrate/primitives/runtime-interface/test/src/lib.rs
with
64 additions
and
41 deletions
substrate/primitives/runtime-interface/test/src/lib.rs
+
64
−
41
View file @
5d5cc9a0
...
...
@@ -176,62 +176,85 @@ fn test_versionining_register_only() {
call_wasm_method
::
<
HostFunctions
>
(
wasm_binary_unwrap
(),
"test_versionning_register_only_works"
);
}
fn
run_test_in_another_process
(
test_name
:
&
str
,
test_body
:
impl
FnOnce
(),
)
->
Option
<
std
::
process
::
Output
>
{
if
std
::
env
::
var
(
"RUN_FORKED_TEST"
)
.is_ok
()
{
test_body
();
None
}
else
{
let
output
=
std
::
process
::
Command
::
new
(
std
::
env
::
current_exe
()
.unwrap
())
.arg
(
test_name
)
.env
(
"RUN_FORKED_TEST"
,
"1"
)
.output
()
.unwrap
();
assert!
(
output
.status
.success
());
Some
(
output
)
}
}
#[test]
fn
test_tracing
()
{
use
std
::
fmt
;
use
tracing
::
span
::
Id
as
SpanId
;
use
tracing_core
::
field
::{
Field
,
Visit
};
#[derive(Clone)]
struct
TracingSubscriber
(
Arc
<
Mutex
<
Inner
>>
);
struct
FieldConsumer
(
&
'static
str
,
Option
<
String
>
);
impl
Visit
for
FieldConsumer
{
fn
record_debug
(
&
mut
self
,
field
:
&
Field
,
value
:
&
dyn
fmt
::
Debug
)
{
if
field
.name
()
==
self
.0
{
self
.1
=
Some
(
format!
(
"{:?}"
,
value
))
// Run in a different process to ensure that the `Span` is registered with our local
// `TracingSubscriber`.
run_test_in_another_process
(
"test_tracing"
,
||
{
use
std
::
fmt
;
use
tracing
::
span
::
Id
as
SpanId
;
use
tracing_core
::
field
::{
Field
,
Visit
};
#[derive(Clone)]
struct
TracingSubscriber
(
Arc
<
Mutex
<
Inner
>>
);
struct
FieldConsumer
(
&
'static
str
,
Option
<
String
>
);
impl
Visit
for
FieldConsumer
{
fn
record_debug
(
&
mut
self
,
field
:
&
Field
,
value
:
&
dyn
fmt
::
Debug
)
{
if
field
.name
()
==
self
.0
{
self
.1
=
Some
(
format!
(
"{:?}"
,
value
))
}
}
}
}
#[derive(Default)]
struct
Inner
{
spans
:
HashSet
<
String
>
,
}
impl
tracing
::
subscriber
::
Subscriber
for
TracingSubscriber
{
fn
enabled
(
&
self
,
_
:
&
tracing
::
Metadata
)
->
bool
{
true
#[derive(Default)]
struct
Inner
{
spans
:
HashSet
<
String
>
,
}
fn
new_span
(
&
self
,
span
:
&
tracing
::
span
::
Attributes
)
->
tracing
::
Id
{
let
mut
inner
=
self
.0
.lock
()
.unwrap
();
let
id
=
SpanId
::
from_u64
((
inner
.spans
.len
()
+
1
)
as
_
);
let
mut
f
=
FieldConsumer
(
"name"
,
None
);
span
.record
(
&
mut
f
);
inner
.spans
.insert
(
f
.1
.unwrap_or_else
(||
span
.metadata
()
.name
()
.to_owned
()));
id
}
impl
tracing
::
subscriber
::
Subscriber
for
TracingSubscriber
{
fn
enabled
(
&
self
,
_
:
&
tracing
::
Metadata
)
->
bool
{
true
}
fn
record
(
&
self
,
_
:
&
SpanId
,
_
:
&
tracing
::
span
::
Record
)
{}
fn
new_span
(
&
self
,
span
:
&
tracing
::
span
::
Attributes
)
->
tracing
::
Id
{
let
mut
inner
=
self
.0
.lock
()
.unwrap
();
let
id
=
SpanId
::
from_u64
((
inner
.spans
.len
()
+
1
)
as
_
);
let
mut
f
=
FieldConsumer
(
"name"
,
None
);
span
.record
(
&
mut
f
);
inner
.spans
.insert
(
f
.1
.unwrap_or_else
(||
span
.metadata
()
.name
()
.to_owned
()));
id
}
fn
record
_follows_from
(
&
self
,
_
:
&
SpanId
,
_
:
&
SpanI
d
)
{}
fn
record
(
&
self
,
_
:
&
SpanId
,
_
:
&
tracing
::
span
::
Recor
d
)
{}
fn
event
(
&
self
,
_
:
&
tracing
::
Event
)
{}
fn
record_follows_from
(
&
self
,
_
:
&
SpanId
,
_
:
&
SpanId
)
{}
fn
ent
er
(
&
self
,
_
:
&
SpanId
)
{}
fn
ev
ent
(
&
self
,
_
:
&
tracing
::
Event
)
{}
fn
exit
(
&
self
,
_
:
&
SpanId
)
{}
}
fn
enter
(
&
self
,
_
:
&
SpanId
)
{}
let
subscriber
=
TracingSubscriber
(
Default
::
default
());
let
_guard
=
tracing
::
subscriber
::
set_default
(
subscriber
.clone
());
fn
exit
(
&
self
,
_
:
&
SpanId
)
{}
}
// Call some method to generate a trace
call_wasm_method
::
<
HostFunctions
>
(
wasm_binary_unwrap
(),
"test_return_data"
);
let
subscriber
=
TracingSubscriber
(
Default
::
default
());
let
_guard
=
tracing
::
subscriber
::
set_default
(
subscriber
.clone
());
// Call some method to generate a trace
call_wasm_method
::
<
HostFunctions
>
(
wasm_binary_unwrap
(),
"test_return_data"
);
let
inner
=
subscriber
.0
.lock
()
.unwrap
();
assert!
(
inner
.spans
.contains
(
"return_input_version_1"
));
let
inner
=
subscriber
.0
.lock
()
.unwrap
();
assert!
(
inner
.spans
.contains
(
"return_input_version_1"
));
});
}
#[test]
...
...
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