1
1
#![ cfg( all( feature = "tokio" , feature = "zstd" ) ) ]
2
- #![ allow( clippy:: unusual_byte_groupings) ]
3
2
4
3
use std:: {
5
4
io,
6
5
pin:: Pin ,
7
- task:: { Context , Poll } ,
6
+ task:: { ready , Context , Poll } ,
8
7
} ;
9
8
10
9
use async_compression:: tokio:: write:: ZstdEncoder ;
11
10
use tokio:: io:: { AsyncWrite , AsyncWriteExt as _} ;
11
+ use tracing_subscriber:: fmt:: format:: FmtSpan ;
12
12
13
13
/// <https://github.com/Nullus157/async-compression/issues/246>
14
14
#[ tokio:: test]
15
15
async fn issue_246 ( ) {
16
+ tracing_subscriber:: fmt ( )
17
+ . without_time ( )
18
+ . with_ansi ( false )
19
+ . with_level ( false )
20
+ . with_test_writer ( )
21
+ . with_target ( false )
22
+ . with_span_events ( FmtSpan :: NEW )
23
+ . init ( ) ;
16
24
let mut zstd_encoder =
17
25
Transparent :: new ( Trace :: new ( ZstdEncoder :: new ( DelayedShutdown :: default ( ) ) ) ) ;
18
26
zstd_encoder. shutdown ( ) . await . unwrap ( ) ;
@@ -32,39 +40,30 @@ impl<T> Transparent<T> {
32
40
}
33
41
34
42
impl < T : AsyncWrite > AsyncWrite for Transparent < T > {
43
+ #[ tracing:: instrument( name = "Transparent::poll_write" , skip_all, ret) ]
35
44
fn poll_write (
36
45
self : Pin < & mut Self > ,
37
46
cx : & mut Context < ' _ > ,
38
47
buf : & [ u8 ] ,
39
48
) -> Poll < Result < usize , io:: Error > > {
40
- eprintln ! ( "Transparent::poll_write = ..." ) ;
41
- let ret = self . project ( ) . inner . poll_write ( cx, buf) ;
42
- eprintln ! ( "Transparent::poll_write = {:?}" , ret) ;
43
- ret
49
+ self . project ( ) . inner . poll_write ( cx, buf)
44
50
}
45
51
52
+ #[ tracing:: instrument( name = "Transparent::poll_flush" , skip_all, ret) ]
46
53
fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
47
- eprintln ! ( "Transparent::poll_flush = ..." ) ;
48
- let ret = self . project ( ) . inner . poll_flush ( cx) ;
49
- eprintln ! ( "Transparent::poll_flush = {:?}" , ret) ;
50
- ret
54
+ self . project ( ) . inner . poll_flush ( cx)
51
55
}
52
56
53
57
/// To quote the [`AsyncWrite`] docs:
54
58
/// > Invocation of a shutdown implies an invocation of flush.
55
59
/// > Once this method returns Ready it implies that a flush successfully happened before the shutdown happened.
56
60
/// > That is, callers don't need to call flush before calling shutdown.
57
61
/// > They can rely that by calling shutdown any pending buffered data will be written out.
62
+ #[ tracing:: instrument( name = "Transparent::poll_shutdown" , skip_all, ret) ]
58
63
fn poll_shutdown ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
59
- eprintln ! ( "Transparent::poll_shutdown = ..." ) ;
60
64
let mut this = self . project ( ) ;
61
- let ret = match this. inner . as_mut ( ) . poll_flush ( cx) {
62
- Poll :: Ready ( Ok ( ( ) ) ) => this. inner . poll_shutdown ( cx) ,
63
- Poll :: Ready ( Err ( e) ) => Poll :: Ready ( Err ( e) ) ,
64
- Poll :: Pending => Poll :: Pending ,
65
- } ;
66
- eprintln ! ( "Transparent::poll_shutdown = {:?}" , ret) ;
67
- ret
65
+ ready ! ( this. inner. as_mut( ) . poll_flush( cx) ) ?;
66
+ this. inner . poll_shutdown ( cx)
68
67
}
69
68
}
70
69
@@ -78,39 +77,33 @@ pin_project_lite::pin_project! {
78
77
}
79
78
80
79
impl AsyncWrite for DelayedShutdown {
80
+ #[ tracing:: instrument( name = "DelayedShutdown::poll_write" , skip_all, ret) ]
81
81
fn poll_write (
82
82
self : Pin < & mut Self > ,
83
83
cx : & mut Context < ' _ > ,
84
84
buf : & [ u8 ] ,
85
85
) -> Poll < Result < usize , io:: Error > > {
86
- eprintln ! ( "DelayedShutdown::poll_write = ..." ) ;
87
86
let _ = cx;
88
87
self . project ( ) . contents . extend_from_slice ( buf) ;
89
- let ret = Poll :: Ready ( Ok ( buf. len ( ) ) ) ;
90
- eprintln ! ( "DelayedShutdown::poll_write = {:?}" , ret) ;
91
- ret
88
+ Poll :: Ready ( Ok ( buf. len ( ) ) )
92
89
}
93
90
91
+ #[ tracing:: instrument( name = "DelayedShutdown::poll_flush" , skip_all, ret) ]
94
92
fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
95
- eprintln ! ( "DelayedShutdown::poll_flush = ..." ) ;
96
93
let _ = cx;
97
- let ret = Poll :: Ready ( Ok ( ( ) ) ) ;
98
- eprintln ! ( "DelayedShutdown::poll_flush = {:?}" , ret) ;
99
- ret
94
+ Poll :: Ready ( Ok ( ( ) ) )
100
95
}
101
96
97
+ #[ tracing:: instrument( name = "DelayedShutdown::poll_shutdown" , skip_all, ret) ]
102
98
fn poll_shutdown ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
103
- eprintln ! ( "DelayedShutdown::poll_shutdown = ..." ) ;
104
- let ret = match self . project ( ) . num_times_shutdown_called {
99
+ match self . project ( ) . num_times_shutdown_called {
105
100
it @ 0 => {
106
101
* it += 1 ;
107
102
cx. waker ( ) . wake_by_ref ( ) ;
108
103
Poll :: Pending
109
104
}
110
105
_ => Poll :: Ready ( Ok ( ( ) ) ) ,
111
- } ;
112
- eprintln ! ( "DelayedShutdown::poll_shutdown = {:?}" , ret) ;
113
- ret
106
+ }
114
107
}
115
108
}
116
109
@@ -128,28 +121,21 @@ impl<T> Trace<T> {
128
121
}
129
122
130
123
impl < T : AsyncWrite > AsyncWrite for Trace < T > {
124
+ #[ tracing:: instrument( name = "Trace::poll_write" , skip_all, ret) ]
131
125
fn poll_write (
132
126
self : Pin < & mut Self > ,
133
127
cx : & mut Context < ' _ > ,
134
128
buf : & [ u8 ] ,
135
129
) -> Poll < Result < usize , io:: Error > > {
136
- eprintln ! ( "Trace::poll_write = ..." ) ;
137
- let ret = self . project ( ) . inner . poll_write ( cx, buf) ;
138
- eprintln ! ( "Trace::poll_write = {:?}" , ret) ;
139
- ret
130
+ self . project ( ) . inner . poll_write ( cx, buf)
140
131
}
141
-
132
+ # [ tracing :: instrument ( name = "Trace::poll_flush" , skip_all , ret ) ]
142
133
fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
143
- eprintln ! ( "Trace::poll_flush = ..." ) ;
144
- let ret = self . project ( ) . inner . poll_flush ( cx) ;
145
- eprintln ! ( "Trace::poll_flush = {:?}" , ret) ;
146
- ret
134
+ self . project ( ) . inner . poll_flush ( cx)
147
135
}
148
136
137
+ #[ tracing:: instrument( name = "Trace::poll_shutdown" , skip_all, ret) ]
149
138
fn poll_shutdown ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
150
- eprintln ! ( "Trace::poll_shutdown = ..." ) ;
151
- let ret = self . project ( ) . inner . poll_shutdown ( cx) ;
152
- eprintln ! ( "Trace::poll_shutdown = {:?}" , ret) ;
153
- ret
139
+ self . project ( ) . inner . poll_shutdown ( cx)
154
140
}
155
141
}
0 commit comments