1
- use async_std:: future:: ready;
2
- use async_std:: prelude:: * ;
3
- use async_std:: task;
4
1
use async_trait:: async_trait;
5
2
use atcoder_problems_backend:: server:: { run_server, Authentication , GitHubUserResponse } ;
6
3
use rand:: Rng ;
7
4
use serde_json:: { json, Value } ;
8
5
use sql_client:: PgPool ;
9
6
use tide:: Result ;
7
+ use tokio:: task;
10
8
11
9
pub mod utils;
12
10
@@ -42,7 +40,7 @@ async fn setup() -> u16 {
42
40
rng. gen :: < u16 > ( ) % 30000 + 30000
43
41
}
44
42
45
- #[ async_std :: test]
43
+ #[ tokio :: test]
46
44
async fn test_ac_ranking ( ) {
47
45
let port = setup ( ) . await ;
48
46
let server = task:: spawn ( async move {
@@ -51,10 +49,12 @@ async fn test_ac_ranking() {
51
49
. unwrap ( ) ;
52
50
run_server ( pg_pool, MockAuth , port) . await . unwrap ( ) ;
53
51
} ) ;
54
- task :: sleep ( std:: time:: Duration :: from_millis ( 1000 ) ) . await ;
52
+ tokio :: time :: sleep ( std:: time:: Duration :: from_millis ( 1000 ) ) . await ;
55
53
56
- let response = surf:: get ( url ( "/atcoder-api/v3/ac_ranking?from=0&to=10" , port) )
57
- . recv_json :: < Value > ( )
54
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/ac_ranking?from=0&to=10" , port) )
55
+ . await
56
+ . unwrap ( )
57
+ . json :: < Value > ( )
58
58
. await
59
59
. unwrap ( ) ;
60
60
assert_eq ! (
@@ -66,8 +66,10 @@ async fn test_ac_ranking() {
66
66
] )
67
67
) ;
68
68
69
- let response = surf:: get ( url ( "/atcoder-api/v3/ac_ranking?from=1&to=3" , port) )
70
- . recv_json :: < Value > ( )
69
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/ac_ranking?from=1&to=3" , port) )
70
+ . await
71
+ . unwrap ( )
72
+ . json :: < Value > ( )
71
73
. await
72
74
. unwrap ( ) ;
73
75
assert_eq ! (
@@ -78,65 +80,80 @@ async fn test_ac_ranking() {
78
80
] )
79
81
) ;
80
82
81
- let response = surf:: get ( url ( "/atcoder-api/v3/ac_ranking?from=10&to=0" , port) )
82
- . recv_json :: < Value > ( )
83
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/ac_ranking?from=10&to=0" , port) )
84
+ . await
85
+ . unwrap ( )
86
+ . json :: < Value > ( )
83
87
. await
84
88
. unwrap ( ) ;
85
89
assert_eq ! ( response. as_array( ) . unwrap( ) . len( ) , 0 ) ;
86
90
87
- let response = surf :: get ( url ( "/atcoder-api/v3/ac_ranking?from=0&to=2000" , port) )
91
+ let response = reqwest :: get ( url ( "/atcoder-api/v3/ac_ranking?from=0&to=2000" , port) )
88
92
. await
89
93
. unwrap ( ) ;
90
94
assert_eq ! ( response. status( ) , 400 ) ;
91
95
92
- let response = surf :: get ( url ( "/atcoder-api/v3/ac_ranking?from=-1&to=10" , port) )
96
+ let response = reqwest :: get ( url ( "/atcoder-api/v3/ac_ranking?from=-1&to=10" , port) )
93
97
. await
94
98
. unwrap ( ) ;
95
99
assert_eq ! ( response. status( ) , 400 ) ;
96
100
97
- let response = surf:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=u1" , port) )
98
- . recv_json :: < Value > ( )
101
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=u1" , port) )
102
+ . await
103
+ . unwrap ( )
104
+ . json :: < Value > ( )
99
105
. await
100
106
. unwrap ( ) ;
101
107
assert_eq ! ( response, json!( { "count" : 1 , "rank" : 1 } ) ) ;
102
108
103
- let response = surf:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=u2" , port) )
104
- . recv_json :: < Value > ( )
109
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=u2" , port) )
110
+ . await
111
+ . unwrap ( )
112
+ . json :: < Value > ( )
105
113
. await
106
114
. unwrap ( ) ;
107
115
assert_eq ! ( response, json!( { "count" : 2 , "rank" : 0 } ) ) ;
108
116
109
- let response = surf:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=u3" , port) )
110
- . recv_json :: < Value > ( )
117
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=u3" , port) )
118
+ . await
119
+ . unwrap ( )
120
+ . json :: < Value > ( )
111
121
. await
112
122
. unwrap ( ) ;
113
123
assert_eq ! ( response, json!( { "count" : 1 , "rank" : 1 } ) ) ;
114
124
115
- let response = surf:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=U1" , port) )
116
- . recv_json :: < Value > ( )
125
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=U1" , port) )
126
+ . await
127
+ . unwrap ( )
128
+ . json :: < Value > ( )
117
129
. await
118
130
. unwrap ( ) ;
119
131
assert_eq ! ( response, json!( { "count" : 1 , "rank" : 1 } ) ) ;
120
132
121
- let response = surf:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=U2" , port) )
122
- . recv_json :: < Value > ( )
133
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=U2" , port) )
134
+ . await
135
+ . unwrap ( )
136
+ . json :: < Value > ( )
123
137
. await
124
138
. unwrap ( ) ;
125
139
assert_eq ! ( response, json!( { "count" : 2 , "rank" : 0 } ) ) ;
126
140
127
- let response = surf:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=U3" , port) )
128
- . recv_json :: < Value > ( )
141
+ let response = reqwest:: get ( url ( "/atcoder-api/v3/user/ac_rank?user=U3" , port) )
142
+ . await
143
+ . unwrap ( )
144
+ . json :: < Value > ( )
129
145
. await
130
146
. unwrap ( ) ;
131
147
assert_eq ! ( response, json!( { "count" : 1 , "rank" : 1 } ) ) ;
132
148
133
- let response = surf :: get ( url (
149
+ let response = reqwest :: get ( url (
134
150
"/atcoder-api/v3/user/ac_rank?user=does_not_exist" ,
135
151
port,
136
152
) )
137
153
. await
138
154
. unwrap ( ) ;
139
155
assert_eq ! ( response. status( ) , 404 ) ;
140
156
141
- server. race ( ready ( ( ) ) ) . await ;
157
+ server. abort ( ) ;
158
+ server. await . unwrap_err ( ) ;
142
159
}
0 commit comments