Skip to content

Commit 7731817

Browse files
AzrenbethAzrenbeth
Azrenbeth
authored and
Azrenbeth
committed
Wrote sample integration test and added missing "use" statements
1 parent 2bb7982 commit 7731817

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*.data
44
*.old
55
out.sql
6-
*.csv
6+
*.csv
7+
/tests/tmp/**

Cargo.lock

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ postgres-openssl = "0.5.0"
1515
rand = "0.8.0"
1616
rayon = "1.3.0"
1717
string_cache = "0.8.0"
18+
serial_test = "0.5.1"
1819

1920
[dependencies.state-map]
2021
git = "https://github.com/matrix-org/rust-matrix-state-map"

tests/common/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
22
use postgres::Client;
33
use postgres_openssl::MakeTlsConnector;
4-
use std::collections::BTreeMap;
4+
use rand::{distributions::Alphanumeric, thread_rng, Rng};
5+
use std::{borrow::Cow, collections::BTreeMap, fmt};
56

6-
use synapse_compress_state::{PGEscape, StateGroupEntry};
7+
use synapse_compress_state::StateGroupEntry;
78

89
static DB_URL: &str = "postgresql://synapse_user:synapse_pass@localhost/synapse";
910

@@ -14,7 +15,7 @@ pub fn add_contents_to_database(room_id: &str, state_group_map: &BTreeMap<i64, S
1415
let connector = MakeTlsConnector::new(builder.build());
1516

1617
let mut client = Client::connect(DB_URL, connector).unwrap();
17-
18+
1819
// build up the query
1920
let mut sql = "".to_string();
2021

@@ -97,4 +98,4 @@ impl<'a> fmt::Display for PGEscape<'a> {
9798

9899
write!(f, "{}{}{}", delim, self.0, delim)
99100
}
100-
}
101+
}

tests/config_tests.rs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use std::collections::BTreeMap;
2+
3+
use serial_test::serial;
4+
use state_map::StateMap;
5+
use synapse_compress_state::{run, Config, StateGroupEntry};
6+
7+
mod common;
8+
9+
#[test]
10+
#[serial(db)]
11+
fn run_succeeds_without_crashing() {
12+
let mut initial: BTreeMap<i64, StateGroupEntry> = BTreeMap::new();
13+
let mut prev = None;
14+
15+
// This starts with the following structure
16+
//
17+
// 0-1-2-3-4-5-6-7-8-9-10-11-12-13
18+
//
19+
// Each group i has state:
20+
// ('node','is', i)
21+
// ('group', j, 'seen') - for all j less than i
22+
for i in 0i64..=13i64 {
23+
let mut entry = StateGroupEntry {
24+
in_range: true,
25+
prev_state_group: prev,
26+
state_map: StateMap::new(),
27+
};
28+
entry
29+
.state_map
30+
.insert("group", &i.to_string(), "seen".into());
31+
entry.state_map.insert("node", "is", i.to_string().into());
32+
33+
initial.insert(i, entry);
34+
35+
prev = Some(i)
36+
}
37+
38+
common::empty_database();
39+
common::add_contents_to_database("room1", &initial);
40+
41+
let db_url = "postgresql://synapse_user:synapse_pass@localhost/synapse".to_string();
42+
let output_file = "./tests/tmp/output.sql".to_string();
43+
let room_id = "room1".to_string();
44+
let min_state_group = "".to_string();
45+
let min_saved_rows = "".to_string();
46+
let groups_to_compress = "".to_string();
47+
let level_sizes = "3,3".to_string();
48+
let transactions = true;
49+
let graphs = false;
50+
51+
let config = Config::new(
52+
db_url.clone(),
53+
output_file,
54+
room_id.clone(),
55+
min_state_group,
56+
groups_to_compress,
57+
min_saved_rows,
58+
level_sizes,
59+
transactions,
60+
graphs,
61+
);
62+
63+
run(config);
64+
}

0 commit comments

Comments
 (0)