@@ -96,10 +96,7 @@ mod tests {
96
96
// tests, we share the same database. If we want to isolate the tests in
97
97
// the future, we can create a new database for each test.
98
98
99
- create_database_tables ( driver) . await . unwrap ( ) ;
100
-
101
- // todo: truncate tables otherwise they will increase in size over time.
102
- // That's not a problem on CI when the database is always newly created.
99
+ database_setup ( driver) . await ;
103
100
104
101
// Persistent torrents (stats)
105
102
@@ -121,8 +118,22 @@ mod tests {
121
118
handling_the_whitelist:: it_should_remove_an_infohash_from_the_whitelist ( driver) ;
122
119
handling_the_whitelist:: it_should_fail_trying_to_add_the_same_infohash_twice ( driver) ;
123
120
handling_the_whitelist:: it_load_the_whitelist ( driver) ;
121
+ }
124
122
125
- driver. drop_database_tables ( ) . unwrap ( ) ;
123
+ /// It initializes the database schema.
124
+ ///
125
+ /// Since the drop SQL queries don't check if the tables already exist,
126
+ /// we have to create them first, and then drop them.
127
+ ///
128
+ /// The method to drop tables does not use "DROP TABLE IF EXISTS". We can
129
+ /// change this function when we update the `Database::drop_database_tables`
130
+ /// method to use "DROP TABLE IF EXISTS".
131
+ async fn database_setup ( driver : & Arc < Box < dyn Database > > ) {
132
+ create_database_tables ( driver) . await . expect ( "database tables creation failed" ) ;
133
+ driver. drop_database_tables ( ) . expect ( "old database tables deletion failed" ) ;
134
+ create_database_tables ( driver)
135
+ . await
136
+ . expect ( "database tables creation from empty schema failed" ) ;
126
137
}
127
138
128
139
async fn create_database_tables ( driver : & Arc < Box < dyn Database > > ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
0 commit comments