mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-20 04:13:07 +02:00
Add an integration test combining replica and server
This confirms that task changes are replicated via the server.
This commit is contained in:
parent
ebcf9527dc
commit
fb39c90592
8 changed files with 151 additions and 98 deletions
136
Cargo.lock
generated
136
Cargo.lock
generated
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "actix-codec"
|
||||
version = "0.3.0"
|
||||
|
@ -12,7 +14,7 @@ dependencies = [
|
|||
"futures-sink",
|
||||
"log",
|
||||
"pin-project 0.4.28",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
]
|
||||
|
||||
|
@ -23,7 +25,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc"
|
||||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-rt 1.1.1",
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"actix-utils",
|
||||
"derive_more",
|
||||
|
@ -43,7 +45,7 @@ checksum = "452299e87817ae5673910e53c243484ca38be3828db819b6011736fc6982e874"
|
|||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-connect",
|
||||
"actix-rt 1.1.1",
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"actix-threadpool",
|
||||
"actix-utils",
|
||||
|
@ -92,16 +94,6 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "actix-macros"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2f86cd6857c135e6e9fe57b1619a88d1f94a7df34c00e11fe13e64fd3438837"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "actix-router"
|
||||
version = "0.2.7"
|
||||
|
@ -121,24 +113,13 @@ version = "1.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227"
|
||||
dependencies = [
|
||||
"actix-macros 0.1.3",
|
||||
"actix-macros",
|
||||
"actix-threadpool",
|
||||
"copyless",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"smallvec",
|
||||
"tokio 0.2.25",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "actix-rt"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0"
|
||||
dependencies = [
|
||||
"actix-macros 0.2.1",
|
||||
"futures-core",
|
||||
"tokio 1.6.2",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -148,13 +129,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "45407e6e672ca24784baa667c5d32ef109ccdd8d5e0b5ebb9ef8a67f4dfb708e"
|
||||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-rt 1.1.1",
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"actix-utils",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"log",
|
||||
"mio 0.6.23",
|
||||
"mio",
|
||||
"mio-uds",
|
||||
"num_cpus",
|
||||
"slab",
|
||||
|
@ -177,8 +158,8 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47239ca38799ab74ee6a8a94d1ce857014b2ac36f242f70f3f75a66f691e791c"
|
||||
dependencies = [
|
||||
"actix-macros 0.1.3",
|
||||
"actix-rt 1.1.1",
|
||||
"actix-macros",
|
||||
"actix-rt",
|
||||
"actix-server",
|
||||
"actix-service",
|
||||
"log",
|
||||
|
@ -219,7 +200,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "2e9022dec56632d1d7979e59af14f0597a28a830a9c1c7fec8b2327eb9f16b5a"
|
||||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-rt 1.1.1",
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"bitflags",
|
||||
"bytes 0.5.6",
|
||||
|
@ -240,9 +221,9 @@ checksum = "e641d4a172e7faa0862241a20ff4f1f5ab0ab7c279f00c2d4587b77483477b86"
|
|||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-http",
|
||||
"actix-macros 0.1.3",
|
||||
"actix-macros",
|
||||
"actix-router",
|
||||
"actix-rt 1.1.1",
|
||||
"actix-rt",
|
||||
"actix-server",
|
||||
"actix-service",
|
||||
"actix-testing",
|
||||
|
@ -400,7 +381,7 @@ checksum = "b381e490e7b0cfc37ebc54079b0413d8093ef43d14a4e4747083f7fa47a9e691"
|
|||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-http",
|
||||
"actix-rt 1.1.1",
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"base64 0.13.0",
|
||||
"bytes 0.5.6",
|
||||
|
@ -1252,7 +1233,7 @@ dependencies = [
|
|||
"http",
|
||||
"indexmap",
|
||||
"slab",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
"tracing-futures",
|
||||
|
@ -1430,7 +1411,7 @@ dependencies = [
|
|||
"itoa",
|
||||
"pin-project 1.0.7",
|
||||
"socket2",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
"want",
|
||||
|
@ -1741,7 +1722,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"shlex",
|
||||
"tempfile",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"toml",
|
||||
"warp",
|
||||
]
|
||||
|
@ -1791,25 +1772,12 @@ dependencies = [
|
|||
"kernel32-sys",
|
||||
"libc",
|
||||
"log",
|
||||
"miow 0.2.2",
|
||||
"miow",
|
||||
"net2",
|
||||
"slab",
|
||||
"winapi 0.2.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.7.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"miow 0.3.7",
|
||||
"ntapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio-extras"
|
||||
version = "2.0.6"
|
||||
|
@ -1818,7 +1786,7 @@ checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
|
|||
dependencies = [
|
||||
"lazycell",
|
||||
"log",
|
||||
"mio 0.6.23",
|
||||
"mio",
|
||||
"slab",
|
||||
]
|
||||
|
||||
|
@ -1830,7 +1798,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
|
|||
dependencies = [
|
||||
"iovec",
|
||||
"libc",
|
||||
"mio 0.6.23",
|
||||
"mio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1845,15 +1813,6 @@ dependencies = [
|
|||
"ws2_32-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miow"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
|
||||
dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "net2"
|
||||
version = "0.2.37"
|
||||
|
@ -1913,21 +1872,12 @@ dependencies = [
|
|||
"fsevent-sys",
|
||||
"inotify",
|
||||
"libc",
|
||||
"mio 0.6.23",
|
||||
"mio",
|
||||
"mio-extras",
|
||||
"walkdir",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
|
||||
dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.44"
|
||||
|
@ -2470,6 +2420,18 @@ dependencies = [
|
|||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "replica-server-tests"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"actix-rt",
|
||||
"actix-web",
|
||||
"anyhow",
|
||||
"taskchampion",
|
||||
"taskchampion-sync-server",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "resolv-conf"
|
||||
version = "0.7.0"
|
||||
|
@ -3002,7 +2964,7 @@ dependencies = [
|
|||
name = "taskchampion-sync-server"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"actix-rt 2.2.0",
|
||||
"actix-rt",
|
||||
"actix-web",
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
@ -3209,7 +3171,7 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"libc",
|
||||
"memchr",
|
||||
"mio 0.6.23",
|
||||
"mio",
|
||||
"mio-uds",
|
||||
"pin-project-lite 0.1.12",
|
||||
"signal-hook-registry",
|
||||
|
@ -3218,22 +3180,6 @@ dependencies = [
|
|||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aea337f72e96efe29acc234d803a5981cd9a2b6ed21655cd7fc21cfe021e8ec7"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"libc",
|
||||
"mio 0.7.13",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"pin-project-lite 0.2.6",
|
||||
"signal-hook-registry",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "0.2.6"
|
||||
|
@ -3254,7 +3200,7 @@ dependencies = [
|
|||
"futures-util",
|
||||
"log",
|
||||
"pin-project 0.4.28",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"tungstenite",
|
||||
]
|
||||
|
||||
|
@ -3269,7 +3215,7 @@ dependencies = [
|
|||
"futures-sink",
|
||||
"log",
|
||||
"pin-project-lite 0.1.12",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3351,7 +3297,7 @@ dependencies = [
|
|||
"rand 0.7.3",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
|
@ -3370,7 +3316,7 @@ dependencies = [
|
|||
"resolv-conf",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"trust-dns-proto",
|
||||
]
|
||||
|
||||
|
@ -3579,7 +3525,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded 0.6.1",
|
||||
"tokio 0.2.25",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
members = [
|
||||
"taskchampion",
|
||||
"cli",
|
||||
"sync-server"
|
||||
"sync-server",
|
||||
"replica-server-tests"
|
||||
]
|
||||
|
|
|
@ -27,11 +27,12 @@ Assuming that continues, it is unlikely that TaskChampion will ever be recommend
|
|||
|
||||
## Structure
|
||||
|
||||
There are three crates here:
|
||||
There are four crates here:
|
||||
|
||||
* [taskchampion](./taskchampion) - the core of the tool
|
||||
* [taskchampion-cli](./cli) - the command-line binary
|
||||
* [taskchampion-sync-server](./sync-server) - the server against which `task sync` operates
|
||||
* [replica-server-tests](./replica-server-tests) - the server against which `task sync` operates
|
||||
|
||||
## Documentation Generation
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ authors = ["Dustin J. Mitchell <dustin@mozilla.com>"]
|
|||
edition = "2018"
|
||||
name = "taskchampion-cli"
|
||||
version = "0.3.0"
|
||||
publish = false
|
||||
|
||||
build = "build.rs"
|
||||
|
||||
|
|
18
replica-server-tests/Cargo.toml
Normal file
18
replica-server-tests/Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "replica-server-tests"
|
||||
version = "0.3.0"
|
||||
authors = ["Dustin J. Mitchell <dustin@mozilla.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[dependencies.taskchampion-sync-server]
|
||||
path = "../sync-server"
|
||||
|
||||
[dependencies.taskchampion]
|
||||
path = "../taskchampion"
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = "1.0"
|
||||
actix-web = "^3.3.2"
|
||||
actix-rt = "^1.1.1"
|
||||
tempfile = "3"
|
1
replica-server-tests/src/lib.rs
Normal file
1
replica-server-tests/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
// test-only crate
|
84
replica-server-tests/tests/cross-sync.rs
Normal file
84
replica-server-tests/tests/cross-sync.rs
Normal file
|
@ -0,0 +1,84 @@
|
|||
use actix_web::{App, HttpServer};
|
||||
use taskchampion::{Replica, ServerConfig, Status, StorageConfig, Uuid};
|
||||
use taskchampion_sync_server::{storage::InMemoryStorage, Server};
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn cross_sync() -> anyhow::Result<()> {
|
||||
let server = Server::new(Box::new(InMemoryStorage::new()));
|
||||
let httpserver =
|
||||
HttpServer::new(move || App::new().service(server.service())).bind("0.0.0.0:0")?;
|
||||
|
||||
// bind was to :0, so the kernel will have selected an unused port
|
||||
let port = httpserver.addrs()[0].port();
|
||||
|
||||
httpserver.run();
|
||||
|
||||
// set up two replicas, and demonstrate replication between them
|
||||
let mut rep1 = Replica::new(StorageConfig::InMemory.into_storage()?);
|
||||
let mut rep2 = Replica::new(StorageConfig::InMemory.into_storage()?);
|
||||
|
||||
let client_key = Uuid::new_v4();
|
||||
let encryption_secret = b"abc123".to_vec();
|
||||
let make_server = || {
|
||||
ServerConfig::Remote {
|
||||
origin: format!("http://127.0.0.1:{}", port),
|
||||
client_key,
|
||||
encryption_secret: encryption_secret.clone(),
|
||||
}
|
||||
.into_server()
|
||||
};
|
||||
|
||||
let mut serv1 = make_server()?;
|
||||
let mut serv2 = make_server()?;
|
||||
|
||||
// add some tasks on rep1
|
||||
let t1 = rep1.new_task(Status::Pending, "test 1".into())?;
|
||||
let t2 = rep1.new_task(Status::Pending, "test 2".into())?;
|
||||
|
||||
// modify t1
|
||||
let mut t1 = t1.into_mut(&mut rep1);
|
||||
t1.start()?;
|
||||
let t1 = t1.into_immut();
|
||||
|
||||
rep1.sync(&mut serv1)?;
|
||||
rep2.sync(&mut serv2)?;
|
||||
|
||||
// those tasks should exist on rep2 now
|
||||
let t12 = rep2
|
||||
.get_task(t1.get_uuid())?
|
||||
.expect("expected task 1 on rep2");
|
||||
let t22 = rep2
|
||||
.get_task(t2.get_uuid())?
|
||||
.expect("expected task 2 on rep2");
|
||||
|
||||
assert_eq!(t12.get_description(), "test 1");
|
||||
assert_eq!(t12.is_active(), true);
|
||||
assert_eq!(t22.get_description(), "test 2");
|
||||
assert_eq!(t22.is_active(), false);
|
||||
|
||||
// make non-conflicting changes on the two replicas
|
||||
let mut t2 = t2.into_mut(&mut rep1);
|
||||
t2.set_status(Status::Completed)?;
|
||||
let t2 = t2.into_immut();
|
||||
|
||||
let mut t12 = t12.into_mut(&mut rep2);
|
||||
t12.set_status(Status::Completed)?;
|
||||
|
||||
// sync those changes back and forth
|
||||
rep1.sync(&mut serv1)?; // rep1 -> server
|
||||
rep2.sync(&mut serv2)?; // server -> rep2, rep2 -> server
|
||||
rep1.sync(&mut serv1)?; // server -> rep1
|
||||
|
||||
let t1 = rep1
|
||||
.get_task(t1.get_uuid())?
|
||||
.expect("expected task 1 on rep1");
|
||||
assert_eq!(t1.get_status(), Status::Completed);
|
||||
|
||||
let t22 = rep2
|
||||
.get_task(t2.get_uuid())?
|
||||
.expect("expected task 2 on rep2");
|
||||
assert_eq!(t22.get_status(), Status::Completed);
|
||||
|
||||
// note that we just drop the server here..
|
||||
Ok(())
|
||||
}
|
|
@ -3,6 +3,7 @@ name = "taskchampion-sync-server"
|
|||
version = "0.3.0"
|
||||
authors = ["Dustin J. Mitchell <dustin@mozilla.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -20,5 +21,5 @@ env_logger = "^0.8.3"
|
|||
rusqlite = { version = "0.25", features = ["bundled"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "^2.2.0"
|
||||
actix-rt = "^1.1.1"
|
||||
tempfile = "3"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue