@@ -6,7 +6,6 @@ use chrono::{DateTime, Utc};
6
6
use diesel:: ExpressionMethods ;
7
7
use diesel_async:: RunQueryDsl ;
8
8
use insta:: assert_snapshot;
9
- use std:: thread;
10
9
use std:: time:: Duration ;
11
10
12
11
#[ tokio:: test( flavor = "multi_thread" ) ]
@@ -238,7 +237,7 @@ async fn publish_new_crate_rate_limit_doesnt_affect_existing_crates() {
238
237
239
238
#[ tokio:: test( flavor = "multi_thread" ) ]
240
239
async fn publish_existing_crate_rate_limited ( ) {
241
- const RATE_LIMIT : Duration = Duration :: from_millis ( 1000 ) ;
240
+ const RATE_LIMIT : Duration = Duration :: from_secs ( 60 ) ;
242
241
243
242
let ( app, anon, _, token) = TestApp :: full ( )
244
243
. with_rate_limit ( LimitedAction :: PublishUpdate , RATE_LIMIT , 1 )
@@ -293,8 +292,17 @@ async fn publish_existing_crate_rate_limited() {
293
292
rss/updates.xml
294
293
" ) ;
295
294
296
- // Wait for the limit to be up
297
- thread:: sleep ( RATE_LIMIT ) ;
295
+ // Reset the rate limit by updating the database timestamp
296
+ let mut conn = app. db_conn ( ) . await ;
297
+ let past_time = Utc :: now ( ) . naive_utc ( ) - RATE_LIMIT - Duration :: from_secs ( 10 ) ;
298
+
299
+ diesel:: update ( publish_limit_buckets:: table)
300
+ . filter ( publish_limit_buckets:: user_id. eq ( token. as_model ( ) . user_id ) )
301
+ . filter ( publish_limit_buckets:: action. eq ( LimitedAction :: PublishUpdate ) )
302
+ . set ( publish_limit_buckets:: last_refill. eq ( past_time) )
303
+ . execute ( & mut conn)
304
+ . await
305
+ . expect ( "Failed to reset rate limit" ) ;
298
306
299
307
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.2" ) ;
300
308
token. publish_crate ( crate_to_publish) . await . good ( ) ;
0 commit comments