Skip to content

Commit

Permalink
update primitives & rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
elpiel committed Dec 11, 2020
1 parent b0dac8e commit d359380
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 35 additions & 12 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ mod test {
.await;

Mock::given(method("GET"))
.and(path(format!("/leader/channel/{}/last-approved", channel_id)))
.and(path(format!(
"/leader/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved))
.expect(2_u64)
Expand All @@ -331,10 +334,9 @@ mod test {
Mock::given(method("GET"))
.and(path(format!(
"/leader/channel/{}/validator-messages/{}/NewState",
channel_id,
leader_id
channel_id, leader_id
)))
.and(query_param("limit" ,"1"))
.and(query_param("limit", "1"))
.respond_with(ResponseTemplate::new(200).set_body_json(&leader_latest_new_state))
.expect(2_u64)
.mount(&mock_server)
Expand All @@ -348,7 +350,10 @@ mod test {
.await;

Mock::given(method("GET"))
.and(path(format!("/follower/channel/{}/last-approved", channel_id)))
.and(path(format!(
"/follower/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&follower_last_approved))
.expect(2_u64)
Expand Down Expand Up @@ -427,15 +432,21 @@ mod test {
};

Mock::given(method("GET"))
.and(path(format!("/leader/channel/{}/last-approved", channel_id)))
.and(path(format!(
"/leader/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved))
.expect(1_u64)
.mount(&mock_server)
.await;

Mock::given(method("GET"))
.and(path(format!("/follower/channel/{}/last-approved", channel_id)))
.and(path(format!(
"/follower/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&follower_last_approved))
.expect(1_u64)
Expand Down Expand Up @@ -498,8 +509,11 @@ mod test {
};

Mock::given(method("GET"))
.and(path(format!("/leader/channel/{}/last-approved", channel_id)))
.and(query_param("withHeartbeat", "true"))
.and(path(format!(
"/leader/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved))
.expect(1_u64)
.mount(&mock_server)
Expand Down Expand Up @@ -600,7 +614,10 @@ mod test {
.await;

Mock::given(method("GET"))
.and(path(format!("/leader/channel/{}/last-approved", channel_id)))
.and(path(format!(
"/leader/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved))
// The second time we call is from the Follower Validator to get up to date Status of the Campaign
Expand All @@ -616,7 +633,10 @@ mod test {
.await;

Mock::given(method("GET"))
.and(path(format!("/follower/channel/{}/last-approved", channel_id)))
.and(path(format!(
"/follower/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&follower_last_approved))
.expect(2_u64)
Expand Down Expand Up @@ -718,7 +738,10 @@ mod test {
};

Mock::given(method("GET"))
.and(path(format!("/leader/channel/{}/last-approved", channel_id)))
.and(path(format!(
"/leader/channel/{}/last-approved",
channel_id
)))
.and(query_param("withHeartbeat", "true"))
.respond_with(ResponseTemplate::new(200).set_body_json(&leader_last_approved))
// The second time we call is from the Follower Validator to get up to date Status of the Campaign
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(clippy::all)]
#![deny(rust_2018_idioms)]
pub use cache::Cache;
use hyper::{Body, Method, Request, Response, Server, Client};
use hyper::{Body, Client, Method, Request, Response, Server};
use hyper_tls::HttpsConnector;
use std::net::SocketAddr;
use std::sync::Arc;
Expand Down Expand Up @@ -104,7 +104,6 @@ pub async fn serve(
error!(&logger, "server error: {}", e);
}


Ok(())
}

Expand All @@ -131,7 +130,10 @@ async fn handle<C: cache::Client>(
.map(|p_q| {
let string = p_q.to_string();
// the MarketUrl (i.e. ApiUrl) always suffixes the path
string.strip_prefix('/').map(ToString::to_string).unwrap_or(string)
string
.strip_prefix('/')
.map(ToString::to_string)
.unwrap_or(string)
})
.unwrap_or_default();

Expand Down
15 changes: 9 additions & 6 deletions src/market.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use primitives::{
market::{Campaign, StatusType},
supermarket::units_for_slot::response::AdUnit,
AdSlot,
util::ApiUrl,
AdSlot,
};
use reqwest::{Client, Error, StatusCode};
use serde::{Deserialize, Serialize};
Expand All @@ -21,7 +21,11 @@ pub struct MarketApi {
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", from = "ad_slot::ShimResponse", into = "ad_slot::ShimResponse")]
#[serde(
rename_all = "camelCase",
from = "ad_slot::ShimResponse",
into = "ad_slot::ShimResponse"
)]
pub struct AdSlotResponse {
pub slot: AdSlot,
pub accepted_referrers: Vec<Url>,
Expand Down Expand Up @@ -219,9 +223,9 @@ mod ad_slot {

use chrono::{DateTime, Utc};
use reqwest::Url;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};

use primitives::{BigNum, AdSlot, ValidatorId, targeting::Rule};
use primitives::{targeting::Rule, AdSlot, BigNum, ValidatorId};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -302,7 +306,7 @@ mod ad_slot {
description: ad_slot.description,
website: ad_slot.website,
archived: ad_slot.archived,
modified: ad_slot.modified
modified: ad_slot.modified,
}
}
}
Expand All @@ -322,7 +326,6 @@ mod ad_slot {
website: self.website,
archived: self.archived,
modified: self.modified,

}
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/sentry_api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use chrono::Utc;
use futures::future::{try_join_all, TryFutureExt};
use primitives::{Channel, ChannelId, ValidatorDesc, sentry::{
use primitives::{
sentry::{
channel_list::ChannelListQuery, ChannelListResponse, LastApprovedResponse,
ValidatorMessage, ValidatorMessageResponse,
}, util::ApiUrl};
},
util::ApiUrl,
Channel, ChannelId, ValidatorDesc,
};
use reqwest::{Client, Response};
use std::time::Duration;
use thiserror::Error;
Expand Down Expand Up @@ -83,7 +87,10 @@ impl SentryApi {

// if the url is wrong `panic!`
let url = api_url
.join(&format!("channel/{}/last-approved?withHeartbeat=true", channel_id))
.join(&format!(
"channel/{}/last-approved?withHeartbeat=true",
channel_id
))
.expect("Url should be valid");

Ok(self.client.get(url).send().await?.json().await?)
Expand Down
6 changes: 3 additions & 3 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub async fn get_status(
};

let follower = channel.spec.validators.follower();
let follower_la = sentry.get_last_approved(channel.id,&follower).await?;
let follower_la = sentry.get_last_approved(channel.id, &follower).await?;

// setup the messages for the checks
let messages = Messages {
Expand Down Expand Up @@ -271,7 +271,7 @@ pub async fn get_status(
/// Calls SentryApi for the Leader's LastApproved NewState and returns the NewState Balance
async fn fetch_balances(sentry: &SentryApi, channel: &Channel) -> Result<BalancesMap, Error> {
let leader_la = sentry
.get_last_approved(channel.id,&channel.spec.validators.leader())
.get_last_approved(channel.id, &channel.spec.validators.leader())
.await?;

let balances = leader_la
Expand Down Expand Up @@ -324,7 +324,7 @@ async fn is_rejected_state(
};

let latest_new_state = sentry
.get_latest_new_state(channel.id,channel.spec.validators.leader())
.get_latest_new_state(channel.id, channel.spec.validators.leader())
.await?;

let latest_new_state = match latest_new_state {
Expand Down
2 changes: 1 addition & 1 deletion src/units_for_slot_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod units_for_slot_tests {
use super::*;
use chrono::DateTime;
use http::header::USER_AGENT;
use primitives::{Channel, ChannelId, targeting::Rules};
use primitives::{targeting::Rules, Channel, ChannelId};

// User Agent OS: Linux (only in `woothee`)
// User Agent Browser Family: Firefox
Expand Down

0 comments on commit d359380

Please sign in to comment.