Skip to content

Commit

Permalink
fix(e2e): update tests with notion of account prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <brooks@cosmonic.com>

reworked e2e account import/exports

Signed-off-by: Brooks Townsend <brooks@cosmonic.com>

removed unnecessary stream response type

Signed-off-by: Brooks Townsend <brooks@cosmonic.com>

addressed PR concerns

Signed-off-by: Brooks Townsend <brooks@cosmonic.com>
  • Loading branch information
brooksmtownsend committed Jul 18, 2023
1 parent 30b90db commit ecbc0df
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<P: Publisher> Server<P> {
#[instrument(level = "info", skip_all)]
pub async fn serve(mut self) -> anyhow::Result<()> {
while let Some(msg) = self.subscriber.next().await {
if !msg.subject.starts_with(&self.prefix) {
if !msg.subject.starts_with(&self.prefix) && !self.multitenant {
warn!(subject = %msg.subject, "Received message on an invalid subject");
continue;
}
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<P: Publisher> Server<P> {
anyhow::bail!("Found extra components of subject")
}
Ok(ParsedSubject {
account_id: account_id,
account_id,
lattice_id,
category,
operation,
Expand Down
4 changes: 4 additions & 0 deletions test/docker-compose-e2e-multitenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ services:
depends_on:
- nats-core
image: nats:2.9.16-alpine
ports:
- "127.0.0.1:4223:4222"
command: ["-js", "-a", "0.0.0.0", "-c", "/nats/config/nats-leaf-a.conf"]
volumes:
- ./nats/:/nats/config
nats-leaf-b:
depends_on:
- nats-core
image: nats:2.9.16-alpine
ports:
- "127.0.0.1:4224:4222"
command: ["-js", "-a", "0.0.0.0", "-c", "/nats/config/nats-leaf-b.conf"]
volumes:
- ./nats/:/nats/config
Expand Down
13 changes: 9 additions & 4 deletions test/nats/nats-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ accounts: {
users: [
{user: wadm, password: wadm}
]
exports: [
{service: *.wadm.api.>, accounts: [A, B]}
]
# Listen to wasmbus.evt events and wadm API commands from account A and B
# Lattice IDs are unique, so we don't need to add account prefixes for them
imports: [
{stream: {account: A, subject: wasmbus.evt.*}, prefix: Axxx}
{stream: {account: A, subject: wadm.api.>}}
{stream: {account: B, subject: wasmbus.evt.*}, prefix: Ayyy}
{stream: {account: B, subject: wadm.api.>}}
{service: {account: A, subject: wasmbus.ctl.>}, to: Axxx.wasmbus.ctl.>}
{service: {account: B, subject: wasmbus.ctl.>}, to: Ayyy.wasmbus.ctl.>}
]
Expand All @@ -38,8 +39,10 @@ accounts: {
users: [
{user: a, password: a}
]
imports: [
{service: {account: WADM, subject: Axxx.wadm.api.>}, to: wadm.api.>}
]
exports: [
{stream: wadm.api.>, accounts: [WADM]}
{stream: wasmbus.evt.*, accounts: [WADM]}
{service: wasmbus.ctl.>, accounts: [WADM], response_type: stream}
]
Expand All @@ -48,8 +51,10 @@ accounts: {
users: [
{user: b, password: b}
]
imports: [
{service: {account: WADM, subject: Ayyy.wadm.api.>}, to: wadm.api.>}
]
exports: [
{stream: wadm.api.>, accounts: [WADM]}
{stream: wasmbus.evt.*, accounts: [WADM]}
{service: wasmbus.ctl.>, accounts: [WADM], response_type: stream}
]
Expand Down
68 changes: 53 additions & 15 deletions tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ impl ClientInfo {
pub async fn put_manifest(
&self,
manifest: &Manifest,
account_id: Option<&str>,
lattice_id: Option<&str>,
) -> PutModelResponse {
self.put_manifest_raw(
serde_yaml::to_string(manifest).unwrap().into_bytes(),
account_id,
lattice_id,
)
.await
Expand All @@ -202,17 +204,35 @@ impl ClientInfo {
pub async fn put_manifest_from_file(
&self,
file_name: &str,
account_id: Option<&str>,
lattice_id: Option<&str>,
) -> PutModelResponse {
self.put_manifest_raw(self.load_raw_manifest(file_name).await, lattice_id)
.await
self.put_manifest_raw(
self.load_raw_manifest(file_name).await,
account_id,
lattice_id,
)
.await
}

async fn put_manifest_raw(&self, data: Vec<u8>, lattice_id: Option<&str>) -> PutModelResponse {
let subject = format!(
"wadm.api.{}.model.put",
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
);
async fn put_manifest_raw(
&self,
data: Vec<u8>,
account_id: Option<&str>,
lattice_id: Option<&str>,
) -> PutModelResponse {
let subject = if let Some(account) = account_id {
format!(
"{}.wadm.api.{}.model.put",
account,
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
)
} else {
format!(
"wadm.api.{}.model.put",
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
)
};
let msg = self
.client
.request(subject, data.into())
Expand All @@ -225,13 +245,22 @@ impl ClientInfo {
pub async fn deploy_manifest(
&self,
name: &str,
account_id: Option<&str>,
lattice_id: Option<&str>,
version: Option<&str>,
) -> DeployModelResponse {
let subject = format!(
"wadm.api.{}.model.deploy.{name}",
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
);
let subject = if let Some(account) = account_id {
format!(
"{}.wadm.api.{}.model.deploy.{name}",
account,
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
)
} else {
format!(
"wadm.api.{}.model.deploy.{name}",
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
)
};
let data = serde_json::to_vec(&DeployModelRequest {
version: version.map(|s| s.to_owned()),
})
Expand All @@ -248,12 +277,21 @@ impl ClientInfo {
pub async fn undeploy_manifest(
&self,
name: &str,
account_id: Option<&str>,
lattice_id: Option<&str>,
) -> DeployModelResponse {
let subject = format!(
"wadm.api.{}.model.undeploy.{name}",
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
);
let subject = if let Some(account) = account_id {
format!(
"{}.wadm.api.{}.model.undeploy.{name}",
account,
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
)
} else {
format!(
"wadm.api.{}.model.undeploy.{name}",
lattice_id.unwrap_or(DEFAULT_LATTICE_ID)
)
};
let data = serde_json::to_vec(&UndeployModelRequest {
non_destructive: false,
})
Expand Down
26 changes: 17 additions & 9 deletions tests/e2e_multiple_hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async fn run_multiple_host_tests() {
// other tests run
async fn test_no_requirements(client_info: &ClientInfo) {
let resp = client_info
.put_manifest_from_file("simple.yaml", None)
.put_manifest_from_file("simple.yaml", None, None)
.await;

assert_ne!(
Expand All @@ -93,7 +93,9 @@ async fn test_no_requirements(client_info: &ClientInfo) {
"Shouldn't have errored when creating manifest: {resp:?}"
);

let resp = client_info.deploy_manifest("echo-simple", None, None).await;
let resp = client_info
.deploy_manifest("echo-simple", None, None, None)
.await;
assert_ne!(
resp.result,
DeployResult::Error,
Expand Down Expand Up @@ -138,7 +140,9 @@ async fn test_no_requirements(client_info: &ClientInfo) {
.await;

// Undeploy manifest
let resp = client_info.undeploy_manifest("echo-simple", None).await;
let resp = client_info
.undeploy_manifest("echo-simple", None, None)
.await;

assert_ne!(
resp.result,
Expand Down Expand Up @@ -214,7 +218,7 @@ async fn test_no_requirements(client_info: &ClientInfo) {

async fn test_spread_all_hosts(client_info: &ClientInfo) {
let resp = client_info
.put_manifest_from_file("all_hosts.yaml", None)
.put_manifest_from_file("all_hosts.yaml", None, None)
.await;

assert_ne!(
Expand All @@ -225,7 +229,7 @@ async fn test_spread_all_hosts(client_info: &ClientInfo) {

// Deploy manifest
let resp = client_info
.deploy_manifest("echo-all-hosts", None, None)
.deploy_manifest("echo-all-hosts", None, None, None)
.await;
assert_ne!(
resp.result,
Expand Down Expand Up @@ -255,7 +259,7 @@ async fn test_spread_all_hosts(client_info: &ClientInfo) {

async fn test_complex_app(client_info: &ClientInfo) {
let resp = client_info
.put_manifest_from_file("complex.yaml", None)
.put_manifest_from_file("complex.yaml", None, None)
.await;

assert_ne!(
Expand All @@ -265,7 +269,9 @@ async fn test_complex_app(client_info: &ClientInfo) {
);

// Deploy manifest
let resp = client_info.deploy_manifest("complex", None, None).await;
let resp = client_info
.deploy_manifest("complex", None, None, None)
.await;
assert_ne!(
resp.result,
DeployResult::Error,
Expand Down Expand Up @@ -359,7 +365,7 @@ async fn test_complex_app(client_info: &ClientInfo) {
// This test should be run after other tests have finished since we are stopping one of the hosts
async fn test_stop_host_rebalance(client_info: &ClientInfo) {
let resp = client_info
.put_manifest_from_file("host_stop.yaml", None)
.put_manifest_from_file("host_stop.yaml", None, None)
.await;

assert_ne!(
Expand All @@ -369,7 +375,9 @@ async fn test_stop_host_rebalance(client_info: &ClientInfo) {
);

// Deploy manifest
let resp = client_info.deploy_manifest("host-stop", None, None).await;
let resp = client_info
.deploy_manifest("host-stop", None, None, None)
.await;
assert_ne!(
resp.result,
DeployResult::Error,
Expand Down
19 changes: 13 additions & 6 deletions tests/e2e_multitenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const DOCKER_COMPOSE_FILE: &str = "test/docker-compose-e2e-multitenant.yaml";

const MESSAGE_PUB_ACTOR_ID: &str = "MC3QONHYH3FY4KYFCOSVJWIDJG4WA2PVD6FHKR7FFT457GVUTZJYR2TJ";
const NATS_PROVIDER_ID: &str = "VADNMSIML2XGO2X4TPIONTIC55R2UUQGPPDZPAVSC2QD7E76CR77SPW7";
const ACCOUNT_EAST: &str = "Axxx";
const ACCOUNT_WEST: &str = "Ayyy";
const LATTICE_EAST: &str = "wasmcloud-east";
const LATTICE_WEST: &str = "wasmcloud-west";

Expand Down Expand Up @@ -52,7 +54,7 @@ async fn run_multitenant_tests() {

async fn test_basic_separation(client_info: &ClientInfo) -> anyhow::Result<()> {
let resp = client_info
.put_manifest_from_file("simple.yaml", Some(LATTICE_EAST))
.put_manifest_from_file("simple.yaml", Some(ACCOUNT_EAST), Some(LATTICE_EAST))
.await;
assert_ne!(
resp.result,
Expand All @@ -61,7 +63,7 @@ async fn test_basic_separation(client_info: &ClientInfo) -> anyhow::Result<()> {
);

let resp = client_info
.put_manifest_from_file("simple2.yaml", Some(LATTICE_WEST))
.put_manifest_from_file("simple2.yaml", Some(ACCOUNT_WEST), Some(LATTICE_WEST))
.await;
assert_ne!(
resp.result,
Expand All @@ -72,7 +74,7 @@ async fn test_basic_separation(client_info: &ClientInfo) -> anyhow::Result<()> {
eprintln!("Deploying manifests to east and west");

let resp = client_info
.deploy_manifest("echo-simple", Some(LATTICE_EAST), None)
.deploy_manifest("echo-simple", Some(ACCOUNT_EAST), Some(LATTICE_EAST), None)
.await;
assert_ne!(
resp.result,
Expand All @@ -81,7 +83,12 @@ async fn test_basic_separation(client_info: &ClientInfo) -> anyhow::Result<()> {
);

let resp = client_info
.deploy_manifest("messaging-simple", Some(LATTICE_WEST), None)
.deploy_manifest(
"messaging-simple",
Some(ACCOUNT_WEST),
Some(LATTICE_WEST),
None,
)
.await;
assert_ne!(
resp.result,
Expand Down Expand Up @@ -250,7 +257,7 @@ async fn test_basic_separation(client_info: &ClientInfo) -> anyhow::Result<()> {
// Undeploy manifests
eprintln!("Undeploying manifest from east and west");
let resp = client_info
.undeploy_manifest("echo-simple", Some(LATTICE_EAST))
.undeploy_manifest("echo-simple", Some(ACCOUNT_EAST), Some(LATTICE_EAST))
.await;
assert_ne!(
resp.result,
Expand All @@ -259,7 +266,7 @@ async fn test_basic_separation(client_info: &ClientInfo) -> anyhow::Result<()> {
);

let resp = client_info
.undeploy_manifest("messaging-simple", Some(LATTICE_WEST))
.undeploy_manifest("messaging-simple", Some(ACCOUNT_WEST), Some(LATTICE_WEST))
.await;
assert_ne!(
resp.result,
Expand Down

0 comments on commit ecbc0df

Please sign in to comment.