Skip to content

Commit 459307e

Browse files
committed
sentry - units-for-slot fix test and bug:
- db- campaign - fix bug in query - units-for-slot - debug! logging and testing
1 parent 409c977 commit 459307e

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

sentry/src/db/campaign.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,19 @@ pub async fn update_campaign(pool: &DbPool, campaign: &Campaign) -> Result<Campa
219219
pub async fn units_for_slot_get_campaigns(
220220
pool: &DbPool,
221221
deposit_assets: Option<&HashSet<Address>>,
222-
creator: Address,
222+
not_creator: Address,
223223
active_to_ge: DateTime<Utc>,
224224
) -> Result<Vec<Campaign>, PoolError> {
225225
let client = pool.get().await?;
226226

227227
let mut where_clauses = vec![
228228
// Campaign.active.to
229229
"active_to >= $1".to_string(),
230-
// Campaign.creator
231-
"creator = $2".into(),
230+
// Campaign.creator != not_creator
231+
"creator != $2".into(),
232232
];
233233
let mut params: Vec<Box<(dyn ToSql + Sync + Send)>> =
234-
vec![Box::new(active_to_ge), Box::new(creator)];
234+
vec![Box::new(active_to_ge), Box::new(not_creator)];
235235

236236
// Deposit assets
237237
match deposit_assets.cloned() {

sentry/src/routes/units_for_slot.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ where
118118
&app.config,
119119
&Some(query.deposit_assets),
120120
publisher_id,
121+
&app.logger,
121122
)
122123
.await?;
123124

124-
debug!(&app.logger, "Fetched Cache campaigns limited by earner (publisher)"; "campaigns" => campaigns_limited_by_earner.len(), "publisher_id" => %publisher_id);
125+
debug!(&app.logger, "Fetched campaigns limited by earner (publisher)"; "campaigns" => campaigns_limited_by_earner.len(), "publisher_id" => %publisher_id);
125126

126127
// We return those in the result (which means AdView would have those) but we don't actually use them
127128
// we do that in order to have the same variables as the validator, so that the `price` is the same
@@ -177,6 +178,7 @@ async fn get_campaigns(
177178
config: &Config,
178179
deposit_assets: &Option<HashSet<Address>>,
179180
publisher_id: ValidatorId,
181+
logger: &Logger,
180182
) -> Result<Vec<Campaign>, CampaignsError> {
181183
// 1. Fetch active Campaigns: (postgres)
182184
// Creator = publisher_id
@@ -200,6 +202,11 @@ async fn get_campaigns(
200202
.get_multiple_with_ids(active_campaign_ids)
201203
.await?;
202204

205+
debug!(
206+
logger,
207+
"Active Campaigns: {:?}\nRemaining: {:?}", &active_campaign_ids, &campaigns_remaining
208+
);
209+
203210
let campaigns_with_remaining = campaigns_remaining
204211
.into_iter()
205212
.filter_map(|(campaign_id, remaining)| {
@@ -208,9 +215,14 @@ async fn get_campaigns(
208215
// and we have to find the `Campaign` instance
209216
active_campaigns
210217
.iter()
211-
.find(|campaign| campaign.id == campaign_id)
218+
.find(|campaign| {
219+
debug!(logger, "Take {:?} because it's active and not exhausted, i.e. {} (remaining budget) > 0", remaining, campaign_id);
220+
221+
campaign.id == campaign_id
222+
})
212223
.cloned()
213224
} else {
225+
debug!(logger, "Skip {:?} because there's no remaining budget", campaign_id);
214226
None
215227
}
216228
})
@@ -234,6 +246,11 @@ async fn get_campaigns(
234246
.flatten()
235247
.collect::<Vec<_>>();
236248

249+
debug!(
250+
logger,
251+
"Publishers Accounting for channels: {:?}", &publisher_accountings
252+
);
253+
237254
// 3. Filter `Campaign`s, that include the `publisher_id` in the Channel balances.
238255
let (mut campaigns_by_earner, rest_of_campaigns): (Vec<Campaign>, Vec<Campaign>) =
239256
campaigns_with_remaining.into_iter().partition(|campaign| {

sentry/src/routes/units_for_slot_test.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ use primitives::{
1414
AdUnit as ResponseAdUnit, Campaign as ResponseCampaign, UnitsWithPrice,
1515
},
1616
},
17-
targeting::{Function, Rules, Value},
17+
targeting::Rules,
1818
test_util::{CAMPAIGNS, DUMMY_AD_UNITS, DUMMY_IPFS, IDS, PUBLISHER},
1919
unified_num::FromWhole,
20+
util::logging::new_logger,
2021
AdSlot,
2122
};
2223

24+
use wiremock::{
25+
matchers::{method, path},
26+
Mock, MockServer, ResponseTemplate,
27+
};
28+
2329
use super::*;
2430
use crate::{
2531
routes::campaign::create_campaign,
2632
test_util::{setup_dummy_app, ApplicationGuard},
2733
Auth,
2834
};
2935

30-
// use url::Url;
31-
use wiremock::{
32-
matchers::{method, path},
33-
Mock, MockServer, ResponseTemplate,
34-
};
35-
3636
// User Agent OS: Linux (only in `woothee`)
3737
// User Agent Browser Family: Firefox
3838
const LINUX_FIREFOX_USER_AGENT: &str =
@@ -47,13 +47,18 @@ async fn setup_mocked_platform_dummy_app() -> (MockServer, ApplicationGuard) {
4747
let platform_url = mock_server.uri().parse().unwrap();
4848

4949
let mut app_guard = setup_dummy_app().await;
50+
app_guard.app.logger = new_logger("sentry-dummy-app");
51+
debug!(
52+
&app_guard.app.logger,
53+
"With platform mocker server at {}", &platform_url
54+
);
55+
5056
app_guard.app.platform_api.platform_url = platform_url;
5157

5258
(mock_server, app_guard)
5359
}
5460

5561
#[tokio::test]
56-
#[ignore = "Fix test"]
5762
async fn test_targeting_input() {
5863
let (mock_server, app_guard) = setup_mocked_platform_dummy_app().await;
5964
let app = Arc::new(app_guard.app);
@@ -71,7 +76,7 @@ async fn test_targeting_input() {
7176
[
7277
(
7378
GANACHE_INFO_1.tokens["Mocked TOKEN 1"].address,
74-
UnifiedNum::from_whole(0.0007),
79+
UnifiedNum::from_whole(0.010),
7580
),
7681
(
7782
GANACHE_INFO_1337.tokens["Mocked TOKEN 1337"].address,
@@ -103,8 +108,7 @@ async fn test_targeting_input() {
103108
deposit,
104109
);
105110

106-
CAMPAIGNS[0] /* .context */
107-
.clone()
111+
CAMPAIGNS[0].clone()
108112
};
109113

110114
let campaign_1 = {
@@ -119,8 +123,7 @@ async fn test_targeting_input() {
119123
deposit,
120124
);
121125

122-
CAMPAIGNS[1] /* .context */
123-
.clone()
126+
CAMPAIGNS[1].clone()
124127
};
125128

126129
let matching_campaign_2 = {
@@ -135,14 +138,7 @@ async fn test_targeting_input() {
135138
deposit,
136139
);
137140

138-
let min_impression_price =
139-
Function::new_only_show_if(Function::new_get("eventMinPrice"));
140-
141-
let mut campaign_2 = CAMPAIGNS[2] /* .context */
142-
.clone();
143-
campaign_2.context.targeting_rules = Rules(vec![min_impression_price.into()]);
144-
145-
campaign_2
141+
CAMPAIGNS[2].clone()
146142
};
147143

148144
[campaign_0, campaign_1, matching_campaign_2]
@@ -253,8 +249,12 @@ async fn test_targeting_input() {
253249
.expect("Should return response")
254250
.0;
255251

256-
// pub targeting_input_base: Input,
257-
// assert_eq!(response.targeting_input_base);
252+
debug!(&app.logger, "{:?}", response.targeting_input_base);
253+
assert_eq!(
254+
response.targeting_input_base.global.publisher_id,
255+
*PUBLISHER
256+
);
257+
258258
assert!(response.accepted_referrers.is_empty());
259259
let expected_fallback_until = ResponseAdUnit {
260260
ipfs: fallback_unit.ipfs,

0 commit comments

Comments
 (0)