Skip to content

Commit 04ca0a5

Browse files
authored
Merge pull request #32 from blacksky-algorithms/fix-ci
Fix CI: ignore tests that require an active database connection + cargo fmt on various crates
2 parents 64efb0a + d750fd8 commit 04ca0a5

File tree

5 files changed

+65
-30
lines changed

5 files changed

+65
-30
lines changed

rsky-common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod env;
2-
pub mod explicit_slurs;
2+
pub mod explicit_slurs;

rsky-feedgen/src/apis/mod.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use rsky_common::env::env_int;
21
use crate::db::*;
3-
use rsky_common::explicit_slurs::contains_explicit_slurs;
42
use crate::models::create_request::CreateRecord;
53
use crate::models::Lexicon::{AppBskyFeedFollow, AppBskyFeedLike, AppBskyFeedPost};
64
use crate::models::*;
@@ -15,6 +13,8 @@ use once_cell::sync::Lazy;
1513
use rand::Rng;
1614
use regex::Regex;
1715
use rocket::State;
16+
use rsky_common::env::env_int;
17+
use rsky_common::explicit_slurs::contains_explicit_slurs;
1818
use rsky_lexicon::app::bsky::embed::{Embeds, MediaUnion};
1919
use rsky_lexicon::app::bsky::feed::PostLabels;
2020
use std::collections::HashSet;
@@ -1109,6 +1109,7 @@ pub async fn get_cursor(
11091109
mod tests {
11101110
use super::*;
11111111
use crate::routes::{index, BLACKSKY};
1112+
use crate::{ReadReplicaConn1, ReadReplicaConn2};
11121113
use rocket::figment::map;
11131114
use rocket::figment::value::{Map, Value};
11141115
use rocket::http::Status;
@@ -1120,33 +1121,46 @@ mod tests {
11201121
fn before(config: FeedGenConfig) -> Rocket<Build> {
11211122
// Initialize Rocket with ReadReplicaConn and other necessary fairings/routes
11221123
let write_database_url = env::var("DATABASE_URL").unwrap();
1123-
let read_database_url = env::var("READ_REPLICA_URL").unwrap();
1124+
let read_database_url_1 = env::var("READ_REPLICA_URL_1").unwrap();
1125+
let read_database_url_2 = env::var("READ_REPLICA_URL_2").unwrap();
11241126

11251127
let write_db: Map<_, Value> = map! {
11261128
"url" => write_database_url.into(),
11271129
"pool_size" => 20.into(),
11281130
"timeout" => 30.into(),
11291131
};
11301132

1131-
let read_db: Map<_, Value> = map! {
1132-
"url" => read_database_url.into(),
1133+
let read_db_1: Map<_, Value> = map! {
1134+
"url" => read_database_url_1.into(),
1135+
"pool_size" => 20.into(),
1136+
"timeout" => 30.into(),
1137+
};
1138+
1139+
let read_db_2: Map<_, Value> = map! {
1140+
"url" => read_database_url_2.into(),
11331141
"pool_size" => 20.into(),
11341142
"timeout" => 30.into(),
11351143
};
11361144

11371145
let figment = rocket::Config::figment().merge((
11381146
"databases",
1139-
map!["pg_read_replica" => read_db, "pg_db" => write_db],
1147+
map![
1148+
"pg_read_replica_1" => read_db_1,
1149+
"pg_read_replica_2" => read_db_2,
1150+
"pg_db" => write_db
1151+
],
11401152
));
11411153

11421154
rocket::custom(figment)
11431155
.attach(WriteDbConn::fairing())
1144-
.attach(ReadReplicaConn::fairing())
1156+
.attach(ReadReplicaConn1::fairing())
1157+
.attach(ReadReplicaConn2::fairing())
11451158
.mount("/", routes![index])
11461159
.manage(config)
11471160
}
11481161

11491162
#[rocket::async_test]
1163+
#[ignore]
11501164
async fn test_no_sponsored_post_when_show_sponsored_post_is_false() {
11511165
// Set environment variables temporarily using temp_env for this test
11521166
async_with_vars(
@@ -1165,6 +1179,7 @@ mod tests {
11651179
show_sponsored_post: false,
11661180
sponsored_post_uri: "at://did:example/sponsored-post".to_string(),
11671181
sponsored_post_probability: 1.0,
1182+
trending_percentile_min: 0.9,
11681183
};
11691184
let rocket = before(config.clone());
11701185

@@ -1205,6 +1220,7 @@ mod tests {
12051220
}
12061221

12071222
#[rocket::async_test]
1223+
#[ignore]
12081224
async fn test_sponsored_post_always_returned_when_probability_is_1() {
12091225
async_with_vars(
12101226
vec![
@@ -1222,6 +1238,7 @@ mod tests {
12221238
show_sponsored_post: true,
12231239
sponsored_post_uri: "at://did:example/sponsored-post".to_string(),
12241240
sponsored_post_probability: 1.0,
1241+
trending_percentile_min: 0.9,
12251242
};
12261243
let rocket = before(config.clone());
12271244

@@ -1261,6 +1278,7 @@ mod tests {
12611278
}
12621279

12631280
#[rocket::async_test]
1281+
#[ignore]
12641282
async fn test_sponsored_post_never_returned_when_limit_is_2() {
12651283
async_with_vars(
12661284
vec![
@@ -1278,6 +1296,7 @@ mod tests {
12781296
show_sponsored_post: true,
12791297
sponsored_post_uri: "at://did:example/sponsored-post".to_string(),
12801298
sponsored_post_probability: 1.0,
1299+
trending_percentile_min: 0.9,
12811300
};
12821301
let rocket = before(config.clone());
12831302

@@ -1318,6 +1337,7 @@ mod tests {
13181337
}
13191338

13201339
#[rocket::async_test]
1340+
#[ignore]
13211341
async fn test_sponsored_post_returned_50_percent_of_the_time() {
13221342
async_with_vars(
13231343
vec![
@@ -1335,6 +1355,7 @@ mod tests {
13351355
show_sponsored_post: true,
13361356
sponsored_post_uri: "at://did:example/sponsored-post".to_string(),
13371357
sponsored_post_probability: 0.5,
1358+
trending_percentile_min: 0.9,
13381359
};
13391360
let rocket = before(config.clone());
13401361

@@ -1387,6 +1408,7 @@ mod tests {
13871408
}
13881409

13891410
#[rocket::async_test]
1411+
#[ignore]
13901412
async fn test_sponsored_post_never_last() {
13911413
async_with_vars(
13921414
vec![
@@ -1404,6 +1426,7 @@ mod tests {
14041426
show_sponsored_post: true,
14051427
sponsored_post_uri: "at://did:example/sponsored-post".to_string(),
14061428
sponsored_post_probability: 1.0,
1429+
trending_percentile_min: 0.9,
14071430
};
14081431
let rocket = before(config.clone());
14091432

rsky-labeler/src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async fn get_labels(
124124

125125
async fn label_subject(
126126
agent: &AtpAgent<MemorySessionStore, ReqwestClient>,
127-
subject_ref: EmitEventInputSubjectRefs
127+
subject_ref: EmitEventInputSubjectRefs,
128128
) -> Result<(), Box<dyn std::error::Error>> {
129129
let label_result = agent
130130
.api
@@ -140,7 +140,8 @@ async fn label_subject(
140140
ModEventLabel {
141141
data: ModEventLabelData {
142142
comment: Some(
143-
env::var("MOD_SERVICE_LABEL_REASON").unwrap_or("Explicit slur filter".to_string()),
143+
env::var("MOD_SERVICE_LABEL_REASON")
144+
.unwrap_or("Explicit slur filter".to_string()),
144145
),
145146
create_label_vals: vec![env::var("MOD_SERVICE_LABEL")
146147
.unwrap_or("antiblack-harassment".to_string())],
@@ -193,7 +194,7 @@ async fn tag_subject(
193194
async fn create_report(
194195
agent: &AtpAgent<MemorySessionStore, ReqwestClient>,
195196
subject_ref: EmitEventInputSubjectRefs,
196-
reason: Option<String>
197+
reason: Option<String>,
197198
) -> Result<(), Box<dyn std::error::Error>> {
198199
let report_result = agent
199200
.api
@@ -362,17 +363,21 @@ async fn process(
362363
continue;
363364
}
364365
if env_bool("ENABLE_CREATE_REPORT").unwrap_or(true) {
365-
match create_report(agent, auto_report.subject_ref.clone(), auto_report.reason).await {
366+
match create_report(
367+
agent,
368+
auto_report.subject_ref.clone(),
369+
auto_report.reason,
370+
)
371+
.await
372+
{
366373
Ok(()) => (),
367374
Err(error) => {
368375
eprintln!("@LOG: Failed to create report for record: {error:?}")
369376
}
370377
}
371378
}
372379
if env_bool("ENABLE_CREATE_LABEL").unwrap_or(true) {
373-
match label_subject(agent, auto_report.subject_ref.clone())
374-
.await
375-
{
380+
match label_subject(agent, auto_report.subject_ref.clone()).await {
376381
Ok(()) => (),
377382
Err(error) => eprintln!("@LOG: Failed to label record: {error:?}"),
378383
}

rsky-lexicon/src/com/atproto/label/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use chrono::{DateTime, Utc};
55
#[derive(Debug, Serialize, Deserialize)]
66
pub struct SubscribeLabels {
77
pub seq: i64,
8-
pub labels: Vec<Label>
8+
pub labels: Vec<Label>,
99
}
1010

1111
/// Metadata tag on an atproto resource (eg, repo or record).

rsky-pds/src/repo/mst/mod.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -488,20 +488,26 @@ impl MST {
488488

489489
// Now, unwrapping is safe because we either already had entries
490490
// or we just set them above
491-
Ok(self.entries.as_mut().ok_or_else(|| anyhow::anyhow!("No entries"))?)
491+
Ok(self
492+
.entries
493+
.as_mut()
494+
.ok_or_else(|| anyhow::anyhow!("No entries"))?)
492495
}
493496

494497
pub fn get_entries_ref(&self) -> Result<Vec<NodeEntry>> {
495498
// If `self.entries` is not populated, hydrate it first
496499
return match self.entries {
497500
None => {
498501
// Read from storage (block store) to get the node data
499-
let data: CborValue = self.storage.clone().read_obj(&self.pointer, |obj: &CborValue| {
500-
match serde_cbor::value::from_value::<NodeData>(obj.clone()) {
501-
Ok(_) => true,
502-
Err(_) => false,
503-
}
504-
})?;
502+
let data: CborValue =
503+
self.storage
504+
.clone()
505+
.read_obj(&self.pointer, |obj: &CborValue| {
506+
match serde_cbor::value::from_value::<NodeData>(obj.clone()) {
507+
Ok(_) => true,
508+
Err(_) => false,
509+
}
510+
})?;
505511
let data: NodeData = serde_cbor::value::from_value(data)?;
506512

507513
// Compute the layer
@@ -513,11 +519,13 @@ impl MST {
513519

514520
// Deserialize into self.entries
515521
util::deserialize_node_data(&self.storage, &data, layer)
516-
},
517-
Some(ref entries) => Ok(entries.clone())
518-
}
522+
}
523+
Some(ref entries) => Ok(entries.clone()),
524+
};
519525
}
520526

527+
// We don't hash the node on every mutation for performance reasons
528+
// Instead we keep track of whether the pointer is outdated and only (recursively) calculate when needed
521529
pub fn get_pointer(&mut self) -> Result<Cid> {
522530
if !self.outdated_pointer {
523531
return Ok(self.pointer);
@@ -583,7 +591,7 @@ impl MST {
583591
bytes: common::struct_to_cbor(data)?,
584592
})
585593
}
586-
594+
587595
/// In most cases, we get the layer of a node from a hint on creation
588596
/// In the case of the topmost node in the tree, we look for a key in the node & determine the layer
589597
/// In the case where we don't find one, we recurse down until we do.
@@ -1211,9 +1219,7 @@ impl MST {
12111219
for entry in self.walk() {
12121220
match entry {
12131221
NodeEntry::Leaf(_) => nodes.push(entry),
1214-
NodeEntry::MST(m) => {
1215-
nodes.push(NodeEntry::MST(m))
1216-
}
1222+
NodeEntry::MST(m) => nodes.push(NodeEntry::MST(m)),
12171223
}
12181224
}
12191225
Ok(nodes)
@@ -1530,6 +1536,7 @@ mod tests {
15301536
}
15311537

15321538
#[test]
1539+
#[ignore]
15331540
fn saves_and_loads_from_blockstore() -> Result<()> {
15341541
let mut storage =
15351542
SqlRepoReader::new(None, "did:example:123456789abcdefghi".to_string(), None);

0 commit comments

Comments
 (0)