Skip to content

Commit c1476d2

Browse files
committed
config tests
1 parent 8209633 commit c1476d2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/config.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,39 @@ pub async fn parse(path: &str) -> Result<Config, Error> {
7777
}
7878
};
7979

80-
// We use addresses as unique identifiers,
81-
// let's make sure they are unique in the config as well.
80+
// Quick config sanity check.
8281
for shard in &config.shards {
82+
// We use addresses as unique identifiers,
83+
// let's make sure they are unique in the config as well.
8384
let mut dup_check = HashSet::new();
85+
let mut primary_count = 0;
8486

8587
for server in &shard.1.servers {
8688
dup_check.insert(server);
89+
90+
// Check that we define only zero or one primary.
91+
match server.2.as_ref() {
92+
"primary" => primary_count += 1,
93+
_ => (),
94+
};
95+
96+
// Check role spelling.
97+
match server.2.as_ref() {
98+
"primary" => (),
99+
"replica" => (),
100+
_ => {
101+
println!(
102+
"> Shard {} server role must be either 'primary' or 'replica', got: '{}'",
103+
shard.0, server.2
104+
);
105+
return Err(Error::BadConfig);
106+
}
107+
};
108+
}
109+
110+
if primary_count > 1 {
111+
println!("> Shard {} has more than on primary configured.", &shard.0);
112+
return Err(Error::BadConfig);
87113
}
88114

89115
if dup_check.len() != shard.1.servers.len() {

tests/sharding/query_routing.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ echo "Giving Postgres 5 seconds to start up..."
88

99
# sleep 5
1010

11-
psql -f query_routing_setup.sql
11+
# psql -f query_routing_setup.sql
1212

1313
psql -h 127.0.0.1 -p 6432 -f query_routing_test_insert.sql
1414

0 commit comments

Comments
 (0)