Skip to content

Commit 4ecc650

Browse files
committed
Split into different tests
Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent 0a366de commit 4ecc650

File tree

12 files changed

+478
-477
lines changed

12 files changed

+478
-477
lines changed

src/common/base/src/base/singleton_instance.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ impl GlobalInstance {
119119
unreachable!("drop_testing should never be called on production global")
120120
}
121121
Singleton::Testing(c) => {
122-
let v = {
123-
let mut guard = c.lock();
124-
guard.remove(thread_name)
125-
};
126-
// We don't care about if about this container any more, just
127-
// move to another thread to make sure this call returned ASAP.
128-
thread::spawn(move || v);
122+
// let v = {
123+
// let mut guard = c.lock();
124+
// guard.remove(thread_name)
125+
// };
126+
// // We don't care about if about this container any more, just
127+
// // move to another thread to make sure this call returned ASAP.
128+
// thread::spawn(move || v);
129129
}
130130
}
131131
}

src/query/service/tests/it/storages/system.rs

Lines changed: 93 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -57,46 +57,6 @@ use wiremock::Mock;
5757
use wiremock::MockServer;
5858
use wiremock::ResponseTemplate;
5959

60-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
61-
async fn test_system_tables() -> Result<()> {
62-
let mut mint = Mint::new("tests/it/storages/testdata");
63-
let file = &mut mint.new_goldenfile("system-tables.txt").unwrap();
64-
65-
// with goldenfile
66-
test_columns_table(file).await.unwrap();
67-
test_configs_table(file).await.unwrap();
68-
test_catalogs_table(file).await.unwrap();
69-
test_databases_table(file).await.unwrap();
70-
test_engines_table(file).await.unwrap();
71-
test_roles_table(file).await.unwrap();
72-
test_settings_table(file).await.unwrap();
73-
test_users_table(file).await.unwrap();
74-
75-
// with assert_eq
76-
test_clusters_table()
77-
.await
78-
.expect("test_clusters_table must succeed");
79-
test_contributors_table()
80-
.await
81-
.expect("test_contributors_table must succeed");
82-
test_credits_table()
83-
.await
84-
.expect("test_credits_table must succeed");
85-
test_functions_table()
86-
.await
87-
.expect("test_functions_table must succeed");
88-
test_metrics_table()
89-
.await
90-
.expect("test_metrics_table must succeed");
91-
test_tables_table()
92-
.await
93-
.expect("test_tables_table must succeed");
94-
test_tracing_table()
95-
.await
96-
.expect("test_tracing_table must succeed");
97-
Ok(())
98-
}
99-
10060
async fn run_table_tests(
10161
file: &mut impl Write,
10262
ctx: Arc<QueryContext>,
@@ -129,6 +89,19 @@ async fn run_table_tests(
12989
Ok(())
13090
}
13191

92+
#[tokio::test]
93+
async fn test_columns_table() -> Result<()> {
94+
let (_guard, ctx) = crate::tests::create_query_context().await?;
95+
96+
let mut mint = Mint::new("tests/it/storages/testdata");
97+
let file = &mut mint.new_goldenfile("columns_table.txt").unwrap();
98+
let table = ColumnsTable::create(1);
99+
100+
run_table_tests(file, ctx, table).await?;
101+
Ok(())
102+
}
103+
104+
#[tokio::test]
132105
async fn test_clusters_table() -> Result<()> {
133106
let (_guard, ctx) = crate::tests::create_query_context().await?;
134107
let table = ClustersTable::create(1);
@@ -143,62 +116,61 @@ async fn test_clusters_table() -> Result<()> {
143116
Ok(())
144117
}
145118

146-
async fn test_columns_table(file: &mut impl Write) -> Result<()> {
147-
let (_guard, ctx) = crate::tests::create_query_context().await?;
148-
let table = ColumnsTable::create(1);
119+
#[tokio::test]
120+
async fn test_configs_table_basic() -> Result<()> {
121+
let mut mint = Mint::new("tests/it/storages/testdata");
122+
let file = &mut mint.new_goldenfile("configs_table_basic.txt").unwrap();
123+
124+
let conf = crate::tests::ConfigBuilder::create().config();
125+
let (_guard, ctx) = crate::tests::create_query_context_with_config(conf, None).await?;
126+
ctx.get_settings().set_max_threads(8)?;
127+
128+
let table = ConfigsTable::create(1);
149129

150130
run_table_tests(file, ctx, table).await?;
131+
151132
Ok(())
152133
}
153134

154-
async fn test_configs_table(file: &mut impl Write) -> Result<()> {
155-
// test_configs_table_basic
156-
{
157-
let conf = crate::tests::ConfigBuilder::create().config();
158-
let (_guard, ctx) = crate::tests::create_query_context_with_config(conf, None).await?;
159-
ctx.get_settings().set_max_threads(8)?;
160-
161-
let table = ConfigsTable::create(1);
162-
163-
run_table_tests(file, ctx, table).await?;
164-
}
135+
#[tokio::test]
136+
async fn test_configs_table_redact() -> Result<()> {
137+
let mut mint = Mint::new("tests/it/storages/testdata");
138+
let file = &mut mint.new_goldenfile("configs_table_redact.txt").unwrap();
139+
140+
let mock_server = MockServer::builder().start().await;
141+
Mock::given(method("HEAD"))
142+
.and(path("/test/.opendal"))
143+
.respond_with(ResponseTemplate::new(404))
144+
.mount(&mock_server)
145+
.await;
146+
147+
let mut conf = crate::tests::ConfigBuilder::create().build();
148+
conf.storage.params = StorageParams::S3(StorageS3Config {
149+
region: "us-east-2".to_string(),
150+
endpoint_url: mock_server.uri(),
151+
bucket: "test".to_string(),
152+
access_key_id: "access_key_id".to_string(),
153+
secret_access_key: "secret_access_key".to_string(),
154+
..Default::default()
155+
});
156+
157+
let (_guard, ctx) = crate::tests::create_query_context_with_config(conf, None).await?;
158+
ctx.get_settings().set_max_threads(8)?;
159+
160+
let table = ConfigsTable::create(1);
161+
let source_plan = table.read_plan(ctx.clone(), None).await?;
165162

166-
// test_configs_table_redact
167-
{
168-
let mock_server = MockServer::builder().start().await;
169-
Mock::given(method("HEAD"))
170-
.and(path("/test/.opendal"))
171-
.respond_with(ResponseTemplate::new(404))
172-
.mount(&mock_server)
173-
.await;
174-
175-
let mut conf = crate::tests::ConfigBuilder::create().build();
176-
conf.storage.params = StorageParams::S3(StorageS3Config {
177-
region: "us-east-2".to_string(),
178-
endpoint_url: mock_server.uri(),
179-
bucket: "test".to_string(),
180-
access_key_id: "access_key_id".to_string(),
181-
secret_access_key: "secret_access_key".to_string(),
182-
..Default::default()
183-
});
184-
185-
let (_guard, ctx) = crate::tests::create_query_context_with_config(conf, None).await?;
186-
ctx.get_settings().set_max_threads(8)?;
187-
188-
let table = ConfigsTable::create(1);
189-
let source_plan = table.read_plan(ctx.clone(), None).await?;
190-
191-
let stream = table.read_data_block_stream(ctx, &source_plan).await?;
192-
let result = stream.try_collect::<Vec<_>>().await?;
193-
let block = &result[0];
194-
assert_eq!(block.num_columns(), 4);
195-
// need a method to skip/edit endpoint_url
196-
// run_table_tests(file, ctx, table).await?;
197-
}
163+
let stream = table.read_data_block_stream(ctx, &source_plan).await?;
164+
let result = stream.try_collect::<Vec<_>>().await?;
165+
let block = &result[0];
166+
assert_eq!(block.num_columns(), 4);
167+
// need a method to skip/edit endpoint_url
168+
// run_table_tests(file, ctx, table).await?;
198169

199170
Ok(())
200171
}
201172

173+
#[tokio::test]
202174
async fn test_contributors_table() -> Result<()> {
203175
let (_guard, ctx) = crate::tests::create_query_context().await?;
204176
let table = ContributorsTable::create(1);
@@ -211,6 +183,7 @@ async fn test_contributors_table() -> Result<()> {
211183
Ok(())
212184
}
213185

186+
#[tokio::test]
214187
async fn test_credits_table() -> Result<()> {
215188
let (_guard, ctx) = crate::tests::create_query_context().await?;
216189
let table = CreditsTable::create(1);
@@ -223,30 +196,43 @@ async fn test_credits_table() -> Result<()> {
223196
Ok(())
224197
}
225198

226-
async fn test_catalogs_table(file: &mut impl Write) -> Result<()> {
199+
#[tokio::test]
200+
async fn test_catalogs_table() -> Result<()> {
201+
let mut mint = Mint::new("tests/it/storages/testdata");
202+
let file = &mut mint.new_goldenfile("catalogs_table.txt").unwrap();
203+
227204
let (_guard, ctx) = crate::tests::create_query_context().await?;
228205
let table = CatalogsTable::create(1);
229206

230207
run_table_tests(file, ctx, table).await?;
231208
Ok(())
232209
}
233210

234-
async fn test_databases_table(file: &mut impl Write) -> Result<()> {
211+
#[tokio::test]
212+
async fn test_databases_table() -> Result<()> {
235213
let (_guard, ctx) = crate::tests::create_query_context().await?;
236214
let table = DatabasesTable::create(1);
237215

216+
let mut mint = Mint::new("tests/it/storages/testdata");
217+
let file = &mut mint.new_goldenfile("databases_table.txt").unwrap();
218+
238219
run_table_tests(file, ctx, table).await?;
239220
Ok(())
240221
}
241222

242-
async fn test_engines_table(file: &mut impl Write) -> Result<()> {
223+
#[tokio::test]
224+
async fn test_engines_table() -> Result<()> {
243225
let (_guard, ctx) = crate::tests::create_query_context().await?;
244226
let table = EnginesTable::create(1);
245227

228+
let mut mint = Mint::new("tests/it/storages/testdata");
229+
let file = &mut mint.new_goldenfile("engines_table.txt").unwrap();
230+
246231
run_table_tests(file, ctx, table).await?;
247232
Ok(())
248233
}
249234

235+
#[tokio::test]
250236
async fn test_functions_table() -> Result<()> {
251237
let (_guard, ctx) = crate::tests::create_query_context().await?;
252238
let table = FunctionsTable::create(1);
@@ -259,6 +245,7 @@ async fn test_functions_table() -> Result<()> {
259245
Ok(())
260246
}
261247

248+
#[tokio::test]
262249
async fn test_metrics_table() -> Result<()> {
263250
init_default_metrics_recorder();
264251
let (_guard, ctx) = crate::tests::create_query_context().await?;
@@ -281,7 +268,11 @@ async fn test_metrics_table() -> Result<()> {
281268
Ok(())
282269
}
283270

284-
async fn test_roles_table(file: &mut impl Write) -> Result<()> {
271+
#[tokio::test]
272+
async fn test_roles_table() -> Result<()> {
273+
let mut mint = Mint::new("tests/it/storages/testdata");
274+
let file = &mut mint.new_goldenfile("roles_table.txt").unwrap();
275+
285276
let (_guard, ctx) = crate::tests::create_query_context().await?;
286277
let tenant = ctx.get_tenant();
287278
ctx.get_settings().set_max_threads(2)?;
@@ -306,7 +297,11 @@ async fn test_roles_table(file: &mut impl Write) -> Result<()> {
306297
Ok(())
307298
}
308299

309-
async fn test_settings_table(file: &mut impl Write) -> Result<()> {
300+
#[tokio::test]
301+
async fn test_settings_table() -> Result<()> {
302+
let mut mint = Mint::new("tests/it/storages/testdata");
303+
let file = &mut mint.new_goldenfile("settings_table.txt").unwrap();
304+
310305
let (_guard, ctx) = crate::tests::create_query_context().await?;
311306
ctx.get_settings().set_max_threads(2)?;
312307
ctx.get_settings().set_max_memory_usage(1073741824)?;
@@ -317,6 +312,7 @@ async fn test_settings_table(file: &mut impl Write) -> Result<()> {
317312
Ok(())
318313
}
319314

315+
#[tokio::test]
320316
async fn test_tables_table() -> Result<()> {
321317
let (_guard, ctx) = crate::tests::create_query_context().await?;
322318
let table = TablesTableWithoutHistory::create(1);
@@ -384,6 +380,7 @@ async fn test_tables_table() -> Result<()> {
384380
Ok(())
385381
}
386382

383+
#[tokio::test]
387384
async fn test_tracing_table() -> Result<()> {
388385
let (_guard, ctx) = crate::tests::create_query_context().await?;
389386
let table: Arc<dyn Table> = Arc::new(TracingTable::create(1));
@@ -398,7 +395,11 @@ async fn test_tracing_table() -> Result<()> {
398395
Ok(())
399396
}
400397

401-
async fn test_users_table(file: &mut impl Write) -> Result<()> {
398+
#[tokio::test]
399+
async fn test_users_table() -> Result<()> {
400+
let mut mint = Mint::new("tests/it/storages/testdata");
401+
let file = &mut mint.new_goldenfile("users_table.txt").unwrap();
402+
402403
let (_guard, ctx) = crate::tests::create_query_context().await?;
403404
let tenant = ctx.get_tenant();
404405
ctx.get_settings().set_max_threads(2)?;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---------- TABLE INFO ------------
2+
DB.Table: 'system'.'catalogs', Table: catalogs-table_id:1, ver:0, Engine: SystemCatalogs
3+
-------- TABLE CONTENTS ----------
4+
+---------+
5+
| name |
6+
+---------+
7+
| default |
8+
+---------+
9+
10+

0 commit comments

Comments
 (0)