Skip to content

Commit

Permalink
chore: Update to actix-web 2.0.
Browse files Browse the repository at this point in the history
Fix #394. Update the code to actix-web 2.0, but do not use async await syntax except where it made the changes significantly easier. async await syntax will be coming in a series of new pull requests.
  • Loading branch information
fzzzy committed Feb 21, 2020
1 parent 9b54fe7 commit a79434a
Show file tree
Hide file tree
Showing 26 changed files with 1,865 additions and 1,600 deletions.
714 changes: 406 additions & 308 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ edition = "2018"
debug = 1

[dependencies]
actix-web = "^1.0.7"
actix-rt = "0.2"
actix-cors = "0.1"
actix-http = "0.2"
actix-service = "0.4"
actix-http = "1"
actix-web = "2"
actix-rt = "1"
actix-cors = "0.2"
base64 = "0.11.0"
bytes = "0.4"
bytes = "0.5"
cadence = "0.19.1"
chrono = "0.4"
config = "0.9.3"
Expand All @@ -29,8 +28,7 @@ diesel_migrations = { version = "1.4.0", features = ["mysql"] }
docopt = "1.1.0"
env_logger = "0.7.1"
failure = "0.1.6"
# do not upgrade futures!
futures = "0.1.28"
futures = { version = "0.3", features = ["compat"] }
googleapis-raw = { version = "0", path = "../mozilla-rust-sdk/googleapis-raw" }
grpcio = { version = "0.5.0-alpha.5" }
lazy_static = "1.4.0"
Expand Down Expand Up @@ -62,7 +60,7 @@ slog-scope = "4.3"
slog-stdlog = "4.0"
slog-term = "2.4"
time = "0.1.42"
tokio-threadpool = "0.1.16"
tokio = "0.2.9"
url = "2.1.0"
uuid = { version = "0.8.1", features = ["serde", "v4"] }
validator = "0.10"
Expand Down
788 changes: 473 additions & 315 deletions db-tests/Cargo.lock

Large diffs are not rendered by default.

53 changes: 17 additions & 36 deletions db-tests/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,16 @@ async fn create_delete() -> Result<()> {

let uid = 1;
let coll = "clients";
let id = db.create_batch(cb(uid, coll, vec![])).compat().await?;
assert!(
db.validate_batch(vb(uid, coll, id.clone()))
.compat()
.await?
);
let id = db.create_batch(cb(uid, coll, vec![])).await?;
assert!(db.validate_batch(vb(uid, coll, id.clone())).await?);

db.delete_batch(params::DeleteBatch {
user_id: hid(uid),
collection: coll.to_owned(),
id: id.clone(),
})
.compat()
.await?;
assert!(!db.validate_batch(vb(uid, coll, id)).compat().await?);
assert!(!db.validate_batch(vb(uid, coll, id)).await?);
Ok(())
}

Expand All @@ -79,18 +74,14 @@ async fn expiry() -> Result<()> {
let uid = 1;
let coll = "clients";
let id = with_delta!(db, -(BATCH_LIFETIME + 11), {
db.create_batch(cb(uid, coll, vec![])).compat().await
db.create_batch(cb(uid, coll, vec![])).await
})?;
assert!(
!db.validate_batch(vb(uid, coll, id.clone()))
.compat()
.await?
);
let result = db.get_batch(gb(uid, coll, id.clone())).compat().await?;
assert!(!db.validate_batch(vb(uid, coll, id.clone())).await?);
let result = db.get_batch(gb(uid, coll, id.clone())).await?;
assert!(result.is_none());

let bsos = vec![postbso("b0", Some("payload 0"), Some(10), None)];
let result = db.append_to_batch(ab(uid, coll, id, bsos)).compat().await;
let result = db.append_to_batch(ab(uid, coll, id, bsos)).await;
let is_batch_not_found = match result.unwrap_err().kind() {
ApiErrorKind::Db(dbe) => match dbe.kind() {
DbErrorKind::BatchNotFound => true,
Expand All @@ -108,24 +99,18 @@ async fn update() -> Result<()> {

let uid = 1;
let coll = "clients";
let id = db.create_batch(cb(uid, coll, vec![])).compat().await?;
assert!(db
.get_batch(gb(uid, coll, id.clone()))
.compat()
.await?
.is_some());
let id = db.create_batch(cb(uid, coll, vec![])).await?;
assert!(db.get_batch(gb(uid, coll, id.clone())).await?.is_some());
// XXX: now bogus under spanner
//assert_eq!(batch.bsos, "".to_owned());

let bsos = vec![
postbso("b0", Some("payload 0"), Some(10), None),
postbso("b1", Some("payload 1"), Some(1_000_000_000), None),
];
db.append_to_batch(ab(uid, coll, id.clone(), bsos))
.compat()
.await?;
db.append_to_batch(ab(uid, coll, id.clone(), bsos)).await?;

assert!(db.get_batch(gb(uid, coll, id)).compat().await?.is_some());
assert!(db.get_batch(gb(uid, coll, id)).await?.is_some());
// XXX: now bogus under spanner
//assert_ne!(batch.bsos, "".to_owned());
Ok(())
Expand All @@ -141,37 +126,33 @@ async fn append_commit() -> Result<()> {
postbso("b0", Some("payload 0"), Some(10), None),
postbso("b1", Some("payload 1"), Some(1_000_000_000), None),
];
let id = db.create_batch(cb(uid, coll, bsos1)).compat().await?;
let id = db.create_batch(cb(uid, coll, bsos1)).await?;

let bsos2 = vec![postbso("b2", Some("payload 2"), None, Some(1000))];
db.append_to_batch(ab(uid, coll, id.clone(), bsos2))
.compat()
.await?;
db.append_to_batch(ab(uid, coll, id.clone(), bsos2)).await?;

let batch = db.get_batch(gb(uid, coll, id)).compat().await?.unwrap();
let batch = db.get_batch(gb(uid, coll, id)).await?.unwrap();
let result = db
.commit_batch(params::CommitBatch {
user_id: hid(uid),
collection: coll.to_owned(),
batch,
})
.compat()
.await?;

debug!("result: {:?}", &result);
assert!(db.get_bso(gbso(uid, coll, "b0")).compat().await?.is_some());
assert!(db.get_bso(gbso(uid, coll, "b2")).compat().await?.is_some());
assert!(db.get_bso(gbso(uid, coll, "b0")).await?.is_some());
assert!(db.get_bso(gbso(uid, coll, "b2")).await?.is_some());

let ts = db
.get_collection_timestamp(params::GetCollectionTimestamp {
user_id: hid(uid),
collection: coll.to_owned(),
})
.compat()
.await?;
assert_eq!(result.modified, ts);

let bso = db.get_bso(gbso(uid, coll, "b1")).compat().await?.unwrap();
let bso = db.get_bso(gbso(uid, coll, "b1")).await?.unwrap();
assert_eq!(bso.sortindex, Some(1_000_000_000));
assert_eq!(bso.payload, "payload 1");
Ok(())
Expand Down
Loading

0 comments on commit a79434a

Please sign in to comment.