Skip to content

Commit ca514f4

Browse files
authored
Merge pull request #1304 from golemfactory/market/default-subscription-ttl-restore-1h
[mkt] Restore 1h as default Offer/Demand TTL
2 parents eabcd70 + 6c86a83 commit ca514f4

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

agent/provider/src/market/provider_market.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ pub struct NewAgreement {
7373
// =========================================== //
7474

7575
/// Sent when subscribing offer to the market will be finished.
76-
#[rtype(result = "Result<()>")]
7776
#[derive(Debug, Clone, Message)]
77+
#[rtype(result = "Result<()>")]
7878
struct Subscription {
7979
id: String,
8080
preset: Preset,

core/market/src/config.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use structopt::StructOpt;
55
pub struct Config {
66
#[structopt(flatten)]
77
pub discovery: DiscoveryConfig,
8-
#[structopt(skip)]
8+
#[structopt(flatten)]
99
pub subscription: SubscriptionConfig,
10-
#[structopt(skip)]
10+
#[structopt(flatten)]
1111
pub events: EventsConfig,
1212
}
1313

@@ -33,37 +33,40 @@ pub struct SubscriptionConfig {
3333
pub default_ttl: chrono::Duration,
3434
}
3535

36-
#[derive(Clone)]
36+
#[derive(StructOpt, Clone)]
3737
pub struct EventsConfig {
38+
#[structopt(env = "MAX_MARKET_EVENTS_DEFAULT", default_value = "20")]
3839
pub max_events_default: i32,
40+
#[structopt(env = "MAX_MARKET_EVENTS_MAX", default_value = "100")]
3941
pub max_events_max: i32,
4042
}
4143

4244
impl Config {
4345
pub fn from_env() -> Result<Config, structopt::clap::Error> {
44-
// Mock command line arguments, because we want to use ENV fallback
45-
// or default values if ENV variables don't exist.
46-
Ok(Config::from_iter_safe(vec!["yagna"].iter())?)
46+
// Empty command line arguments, because we want to use ENV fallback
47+
// or default values if ENV variables are not set.
48+
Ok(Config::from_iter_safe(&[""])?)
4749
}
4850
}
4951

50-
impl Default for SubscriptionConfig {
51-
fn default() -> Self {
52-
SubscriptionConfig {
53-
default_ttl: chrono::Duration::seconds(50),
54-
}
55-
}
52+
fn parse_chrono_duration(s: &str) -> Result<chrono::Duration, anyhow::Error> {
53+
Ok(chrono::Duration::from_std(humantime::parse_duration(s)?)?)
5654
}
5755

58-
impl Default for EventsConfig {
59-
fn default() -> Self {
60-
EventsConfig {
61-
max_events_default: 20,
62-
max_events_max: 100,
63-
}
56+
#[cfg(test)]
57+
mod test {
58+
use super::Config;
59+
60+
#[test]
61+
fn test_default_structopt_subscription_ttl() {
62+
let c = Config::from_env().unwrap();
63+
assert_eq!(60, c.subscription.default_ttl.num_minutes());
6464
}
65-
}
6665

67-
fn parse_chrono_duration(s: &str) -> Result<chrono::Duration, anyhow::Error> {
68-
Ok(chrono::Duration::from_std(humantime::parse_duration(s)?)?)
66+
#[test]
67+
fn test_default_structopt_events() {
68+
let c = Config::from_env().unwrap();
69+
assert_eq!(20, c.events.max_events_default);
70+
assert_eq!(100, c.events.max_events_max);
71+
}
6972
}

core/market/src/testing/mock_node.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use anyhow::{anyhow, bail, Context, Result};
55
use regex::Regex;
66
use std::collections::HashMap;
77
use std::{fs, path::PathBuf, sync::Arc, time::Duration};
8+
use structopt::StructOpt;
89

910
use ya_client::model::market::RequestorEvent;
1011
use ya_persistence::executor::DbExecutor;
@@ -20,7 +21,7 @@ use super::bcast::BCastService;
2021
use super::mock_net::{gsb_prefixes, MockNet};
2122
use super::negotiation::{provider, requestor};
2223
use super::{store::SubscriptionStore, Matcher};
23-
use crate::config::{Config, DiscoveryConfig};
24+
use crate::config::{Config, DiscoveryConfig, EventsConfig, SubscriptionConfig};
2425
use crate::db::dao::ProposalDao;
2526
use crate::db::model::{Demand, Offer, Proposal, ProposalId, SubscriptionId};
2627
use crate::identity::IdentityApi;
@@ -680,8 +681,8 @@ pub fn create_market_config_for_test() -> Config {
680681

681682
Config {
682683
discovery,
683-
subscription: Default::default(),
684-
events: Default::default(),
684+
subscription: SubscriptionConfig::from_iter(&[""]),
685+
events: EventsConfig::from_iter(&[""]),
685686
}
686687
}
687688

0 commit comments

Comments
 (0)