-
Notifications
You must be signed in to change notification settings - Fork 30
feat: fix asserts on client dis/connect and convert inc call to rust #1178
Conversation
a9b6fc9
to
c1756f3
Compare
fn process_increment_storage(&mut self) -> ClientState { | ||
// Let the variable copies begin, so that nothing is left dangling in the future | ||
// we then assemble because Lifetimes. | ||
let webpush = self.webpush.as_ref().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing that these unwraps are gets trapped up by client.transition()? Should we call these out as specific errors if they fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically to get to the point where we can do state transitions, we need a webpush here, same with how the state machine guarantee's we'll have unacked by this point or we wouldn't need to increment storage.
autopush_rs/src/server/mod.rs
Outdated
@@ -338,9 +342,19 @@ impl Server { | |||
} else { | |||
ServiceChangeTracker::new(Vec::new()) | |||
}; | |||
let region = if env::var("AWS_PROFILE").unwrap_or("default".to_string()) == "test" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use if cfg!(test)
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we set what ever that checks somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg!()
can be called at run time to see what configuration you happen to be in. It's the inline equivalent of "#[cfg(test)]".
It might be more useful than checking the AWS_PROFILE for a test configuration value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, how do we flag in the environment that its in test mode? It's not running a Rust based test suite that would flag this afaik.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the #cfg test toggle is via a compiler flag, so unfortunately we can't use it here.
The python code keys on AWS_LOCAL_DYNAMODB, so I'd rather this key on that as well. Then I don't think the changes to .travis.yml/boto.cfg/tox.ini are necessary (and local testing should continue to work as normal)
Codecov Report
@@ Coverage Diff @@
## master #1178 +/- ##
======================================
Coverage 100% 100%
======================================
Files 60 60
Lines 10078 10078
======================================
Hits 10078 10078 Continue to review full report at Codecov.
|
autopush_rs/src/server/mod.rs
Outdated
debug!("Disconnecting client!"); | ||
let mut uaids = self.uaids.borrow_mut(); | ||
uaids.remove(uaid).expect("uaid not registered"); | ||
let client_exists = if let Some(client) = uaids.get(uaid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: could go with a one liner: let client_exists = uaids.get(uaid).map(|client| client.uid == *uid).unwrap_or(false);
autopush_rs/src/util/ddb_helpers.rs
Outdated
/// A bunch of macro helpers from rusoto_helpers code, which they pulled from crates.io because | ||
/// they were waiting for rusuto to hit 1.0.0 or something. For sanity, they are instead accumulated | ||
/// here for our use. | ||
macro_rules! attributes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these first 3 should have #[allow(unused_macros)] for now to quiet rustc warnings
c1756f3
to
2c45ec9
Compare
autopush_rs/src/server/mod.rs
Outdated
@@ -338,9 +342,19 @@ impl Server { | |||
} else { | |||
ServiceChangeTracker::new(Vec::new()) | |||
}; | |||
let region = if env::var("AWS_PROFILE").unwrap_or("default".to_string()) == "test" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the #cfg test toggle is via a compiler flag, so unfortunately we can't use it here.
The python code keys on AWS_LOCAL_DYNAMODB, so I'd rather this key on that as well. Then I don't think the changes to .travis.yml/boto.cfg/tox.ini are necessary (and local testing should continue to work as normal)
autopush_rs/src/server/mod.rs
Outdated
name: "local_dynamodb".to_string(), | ||
} | ||
} else { | ||
Region::UsEast1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't hardcode, you want Region::default() so it's read from the AWS_DEFAULT_REGION env var
2c45ec9
to
b15f89a
Compare
Removes the asserts when adding the uaid to the uaids hash, and issue proper disconnect call to existing client. Ensure uaid removal removes the right client indicated by a separate UUID per client object. Convert IncrementStorage call to pure Rust async and remove Python implementation. Closes #1177
b15f89a
to
a481959
Compare
@@ -338,9 +342,17 @@ impl Server { | |||
} else { | |||
ServiceChangeTracker::new(Vec::new()) | |||
}; | |||
let region = env::var("AWS_LOCAL_DYNAMODB").map(|endpoint| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: unwrap_or_else would be preferred here (don't care much because this is for tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it needs to construct the Region object with the value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the fallback I mean (oops I annotated the wrong line). it's just the lazy version of unwrap_or
.unwrap_or_else(|| Region::default());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwrap_or_else(Region::default) even!
@@ -28,7 +28,7 @@ install: | |||
- pip install tox ${CODECOV:+codecov} | |||
- if [ ${WITH_RUST:-true} != "false" ]; then curl https://sh.rustup.rs | sh -s -- -y || travis_terminate 1; fi | |||
- export PATH=$PATH:$HOME/.cargo/bin | |||
- export AWS_SHARED_CREDENTIALS_FILE=./automock/credentials.cfg | |||
- export AWS_SHARED_CREDENTIALS_FILE=./automock/boto.cfg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this and the boto.cfg change still necessary? (boto.cfg should probably be killed at this point if anything)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, because rusoto wants to find itself some aws access/secret keys, and if it can't find them in a file it expects, it starts issuing HTTP calls looking for IAM keys and such which messes things up. This is also why I added random access/secret keys to the boto.cfg. (There is no credentials.cfg)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but credentials.cfg has them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What credentials.cfg? https://github.com/mozilla-services/autopush/tree/master/automock
Removes the asserts when adding the uaid to the uaids hash, and issue
proper disconnect call to existing client. Ensure uaid removal removes
the right client indicated by a separate UUID per client object.
Convert IncrementStorage call to pure Rust async and remove Python
implementation.
Closes #1177