@@ -18,7 +18,6 @@ use crate::{metrics::Metrics, ParticipationPriority};
18
18
use :: test_helpers:: { dummy_candidate_receipt, dummy_hash} ;
19
19
use assert_matches:: assert_matches;
20
20
use polkadot_primitives:: { BlockNumber , Hash } ;
21
- use std:: sync:: Arc ;
22
21
23
22
use super :: { CandidateComparator , ParticipationRequest , QueueError , Queues } ;
24
23
@@ -27,7 +26,7 @@ fn make_participation_request(hash: Hash) -> ParticipationRequest {
27
26
let mut receipt = dummy_candidate_receipt ( dummy_hash ( ) ) ;
28
27
// make it differ:
29
28
receipt. commitments_hash = hash;
30
- let request_timer = Arc :: new ( Metrics :: default ( ) . time_participation_pipeline ( ) ) ;
29
+ let request_timer = Metrics :: default ( ) . time_participation_pipeline ( ) ;
31
30
ParticipationRequest :: new ( receipt, 1 , request_timer)
32
31
}
33
32
@@ -39,6 +38,18 @@ fn make_dummy_comparator(
39
38
CandidateComparator :: new_dummy ( relay_parent, * req. candidate_hash ( ) )
40
39
}
41
40
41
+ /// Make a partial clone of the given ParticipationRequest, just missing
42
+ /// the request_timer field. We prefer this helper to implementing Clone
43
+ /// for ParticipationRequest, since we only clone requests in tests.
44
+ fn clone_request ( request : & ParticipationRequest ) -> ParticipationRequest {
45
+ ParticipationRequest {
46
+ candidate_receipt : request. candidate_receipt . clone ( ) ,
47
+ candidate_hash : request. candidate_hash . clone ( ) ,
48
+ session : request. session ,
49
+ _request_timer : None ,
50
+ }
51
+ }
52
+
42
53
/// Check that dequeuing acknowledges order.
43
54
///
44
55
/// Any priority item will be dequeued before any best effort items, priority and best effort with
@@ -59,35 +70,35 @@ fn ordering_works_as_expected() {
59
70
. queue_with_comparator (
60
71
make_dummy_comparator ( & req1, Some ( 1 ) ) ,
61
72
ParticipationPriority :: BestEffort ,
62
- req1 . clone ( ) ,
73
+ clone_request ( & req1 ) ,
63
74
)
64
75
. unwrap ( ) ;
65
76
queue
66
77
. queue_with_comparator (
67
78
make_dummy_comparator ( & req_prio, Some ( 1 ) ) ,
68
79
ParticipationPriority :: Priority ,
69
- req_prio . clone ( ) ,
80
+ clone_request ( & req_prio ) ,
70
81
)
71
82
. unwrap ( ) ;
72
83
queue
73
84
. queue_with_comparator (
74
85
make_dummy_comparator ( & req3, Some ( 2 ) ) ,
75
86
ParticipationPriority :: BestEffort ,
76
- req3 . clone ( ) ,
87
+ clone_request ( & req3 ) ,
77
88
)
78
89
. unwrap ( ) ;
79
90
queue
80
91
. queue_with_comparator (
81
92
make_dummy_comparator ( & req_prio_2, Some ( 2 ) ) ,
82
93
ParticipationPriority :: Priority ,
83
- req_prio_2 . clone ( ) ,
94
+ clone_request ( & req_prio_2 ) ,
84
95
)
85
96
. unwrap ( ) ;
86
97
queue
87
98
. queue_with_comparator (
88
99
make_dummy_comparator ( & req5_unknown_parent, None ) ,
89
100
ParticipationPriority :: BestEffort ,
90
- req5_unknown_parent . clone ( ) ,
101
+ clone_request ( & req5_unknown_parent ) ,
91
102
)
92
103
. unwrap ( ) ;
93
104
assert_matches ! (
@@ -132,46 +143,46 @@ fn candidate_is_only_dequeued_once() {
132
143
. queue_with_comparator (
133
144
make_dummy_comparator ( & req1, None ) ,
134
145
ParticipationPriority :: BestEffort ,
135
- req1 . clone ( ) ,
146
+ clone_request ( & req1 ) ,
136
147
)
137
148
. unwrap ( ) ;
138
149
queue
139
150
. queue_with_comparator (
140
151
make_dummy_comparator ( & req_prio, Some ( 1 ) ) ,
141
152
ParticipationPriority :: Priority ,
142
- req_prio . clone ( ) ,
153
+ clone_request ( & req_prio ) ,
143
154
)
144
155
. unwrap ( ) ;
145
156
// Insert same best effort again:
146
157
queue
147
158
. queue_with_comparator (
148
159
make_dummy_comparator ( & req1, None ) ,
149
160
ParticipationPriority :: BestEffort ,
150
- req1 . clone ( ) ,
161
+ clone_request ( & req1 ) ,
151
162
)
152
163
. unwrap ( ) ;
153
164
// insert same prio again:
154
165
queue
155
166
. queue_with_comparator (
156
167
make_dummy_comparator ( & req_prio, Some ( 1 ) ) ,
157
168
ParticipationPriority :: Priority ,
158
- req_prio . clone ( ) ,
169
+ clone_request ( & req_prio ) ,
159
170
)
160
171
. unwrap ( ) ;
161
172
// Insert first as best effort:
162
173
queue
163
174
. queue_with_comparator (
164
175
make_dummy_comparator ( & req_best_effort_then_prio, Some ( 2 ) ) ,
165
176
ParticipationPriority :: BestEffort ,
166
- req_best_effort_then_prio . clone ( ) ,
177
+ clone_request ( & req_best_effort_then_prio ) ,
167
178
)
168
179
. unwrap ( ) ;
169
180
// Then as prio:
170
181
queue
171
182
. queue_with_comparator (
172
183
make_dummy_comparator ( & req_best_effort_then_prio, Some ( 2 ) ) ,
173
184
ParticipationPriority :: Priority ,
174
- req_best_effort_then_prio . clone ( ) ,
185
+ clone_request ( & req_best_effort_then_prio ) ,
175
186
)
176
187
. unwrap ( ) ;
177
188
@@ -183,15 +194,15 @@ fn candidate_is_only_dequeued_once() {
183
194
. queue_with_comparator (
184
195
make_dummy_comparator ( & req_prio_then_best_effort, Some ( 3 ) ) ,
185
196
ParticipationPriority :: Priority ,
186
- req_prio_then_best_effort . clone ( ) ,
197
+ clone_request ( & req_prio_then_best_effort ) ,
187
198
)
188
199
. unwrap ( ) ;
189
200
// Then as best effort:
190
201
queue
191
202
. queue_with_comparator (
192
203
make_dummy_comparator ( & req_prio_then_best_effort, Some ( 3 ) ) ,
193
204
ParticipationPriority :: BestEffort ,
194
- req_prio_then_best_effort . clone ( ) ,
205
+ clone_request ( & req_prio_then_best_effort ) ,
195
206
)
196
207
. unwrap ( ) ;
197
208
0 commit comments