Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Nov 12, 2024
1 parent 73048e4 commit 1cded42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 5 additions & 7 deletions mobile_config/src/gateway_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ pub(crate) mod db {
use std::str::FromStr;

const GET_METADATA_SQL: &str = r#"
select kta.entity_key, infos.location::bigint, infos.device_type
select kta.entity_key, infos.location::bigint, infos.device_type,
infos.refreshed_at, infos.created_at
from mobile_hotspot_infos infos
join key_to_assets kta on infos.asset = kta.asset
"#;
Expand Down Expand Up @@ -179,6 +180,7 @@ pub(crate) mod db {
pub fn all_info_stream<'a>(
db: impl PgExecutor<'a> + 'a,
device_types: &'a [DeviceType],
_min_refreshed_at: i64, // TODO
) -> impl Stream<Item = GatewayInfo> + 'a {
match device_types.is_empty() {
true => sqlx::query_as::<_, GatewayInfo>(GET_METADATA_SQL)
Expand Down Expand Up @@ -213,17 +215,13 @@ pub(crate) mod db {
.as_ref(),
)
.map_err(|err| sqlx::Error::Decode(Box::new(err)))?;
let created_at = row.get::<i64, &str>("created_at");
let created_at = row.get::<DateTime<Utc>, &str>("created_at");
// `refreshed_at` can be NULL in the database schema.
// If so, fallback to using `created_at` as the default value of `refreshed_at`.
let refreshed_at = row
.get::<Option<i64>, &str>("refreshed_at")
.get::<Option<DateTime<Utc>>, &str>("refreshed_at")
.unwrap_or(created_at);

// TODO remove unwraps
let created_at = DateTime::<Utc>::from_timestamp(created_at, 0).unwrap();
let refreshed_at = DateTime::<Utc>::from_timestamp(refreshed_at, 0).unwrap();

Ok(Self {
address: PublicKeyBinary::from_str(
&bs58::encode(row.get::<&[u8], &str>("entity_key")).into_string(),
Expand Down
6 changes: 5 additions & 1 deletion mobile_config/src/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ impl mobile_config::Gateway for GatewayService {
);

tokio::spawn(async move {
let stream = gateway_info::db::all_info_stream(&pool, &device_types);
let stream = gateway_info::db::all_info_stream(
&pool,
&device_types,
request.min_refreshed_at as i64,
);
stream_multi_gateways_info(stream, tx.clone(), signing_key.clone(), batch_size).await
});

Expand Down
4 changes: 3 additions & 1 deletion mobile_config/tests/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ async fn create_db_tables(pool: &PgPool) {
CREATE TABLE mobile_hotspot_infos (
asset character varying(255) NULL,
location numeric NULL,
device_type jsonb NOT NULL
device_type jsonb NOT NULL,
created_at timestamptz NOT NULL DEFAULT NOW(),
refreshed_at timestamptz
);"#,
)
.execute(pool)
Expand Down

0 comments on commit 1cded42

Please sign in to comment.