Fix netrunner tests (#61)
This commit is contained in:
parent
be304046dd
commit
be5df9ead1
|
@ -20,7 +20,6 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
working-directory: simlib
|
working-directory: simlib
|
||||||
run: cargo build -v
|
run: cargo build -v
|
||||||
# TODO: uncomment this after fixing tests
|
- name: Unit tests
|
||||||
# - name: Unit tests
|
working-directory: simlib
|
||||||
# working-directory: simlib
|
run: cargo test -v
|
||||||
# run: cargo test -v
|
|
||||||
|
|
|
@ -524,7 +524,7 @@ mod tests {
|
||||||
|
|
||||||
impl PayloadSize for () {
|
impl PayloadSize for () {
|
||||||
fn size_bytes(&self) -> u32 {
|
fn size_bytes(&self) -> u32 {
|
||||||
todo!()
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,6 @@ pub fn create_regions<R: Rng>(
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use consensus_engine::NodeId;
|
|
||||||
use rand::rngs::mock::StepRng;
|
use rand::rngs::mock::StepRng;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -164,7 +163,7 @@ mod tests {
|
||||||
regions::{create_regions, Region},
|
regions::{create_regions, Region},
|
||||||
NetworkSettings,
|
NetworkSettings,
|
||||||
},
|
},
|
||||||
node::NodeIdExt,
|
node::{NodeId, NodeIdExt},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::warding::WardCondition;
|
||||||
|
|
||||||
use super::{Node, NodeId};
|
use super::{Node, NodeId};
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)]
|
||||||
|
@ -40,6 +42,16 @@ impl<S> Node for DummyStreamingNode<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn step(&mut self, _: Duration) {
|
fn step(&mut self, _: Duration) {
|
||||||
todo!()
|
self.state.counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn analyze(&self, ward: &mut crate::warding::WardCondition) -> bool {
|
||||||
|
match ward {
|
||||||
|
WardCondition::Max(ward) => self.state.counter >= ward.max_count,
|
||||||
|
WardCondition::Sum(condition) => {
|
||||||
|
*condition.step_result.borrow_mut() += self.state.counter;
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,8 +163,14 @@ impl Node for usize {
|
||||||
self.add_assign(1);
|
self.add_assign(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn analyze(&self, _: &mut WardCondition) -> bool {
|
fn analyze(&self, ward: &mut WardCondition) -> bool {
|
||||||
todo!()
|
match ward {
|
||||||
|
WardCondition::Max(ward) => *self >= ward.max_count,
|
||||||
|
WardCondition::Sum(condition) => {
|
||||||
|
*condition.step_result.borrow_mut() += *self;
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,8 +117,6 @@ where
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{collections::HashMap, time::Duration};
|
use std::{collections::HashMap, time::Duration};
|
||||||
|
|
||||||
use consensus_engine::View;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
network::{
|
network::{
|
||||||
behaviour::NetworkBehaviour,
|
behaviour::NetworkBehaviour,
|
||||||
|
@ -135,12 +133,13 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
struct IORecord {
|
struct IORecord<T> {
|
||||||
states: HashMap<NodeId, View>,
|
states: HashMap<NodeId, T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T: Serialize> TryFrom<&SimulationState<S, T>> for IORecord {
|
impl<S, T: Serialize + Clone> TryFrom<&SimulationState<S, T>> for IORecord<T> {
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn try_from(value: &SimulationState<S, T>) -> Result<Self, Self::Error> {
|
fn try_from(value: &SimulationState<S, T>) -> Result<Self, Self::Error> {
|
||||||
|
@ -148,7 +147,7 @@ mod tests {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
states: nodes
|
states: nodes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|node| (node.id(), node.current_view()))
|
.map(|node| (node.id(), node.state().clone()))
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,8 +103,6 @@ where
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{collections::HashMap, time::Duration};
|
use std::{collections::HashMap, time::Duration};
|
||||||
|
|
||||||
use consensus_engine::View;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
network::{
|
network::{
|
||||||
behaviour::NetworkBehaviour,
|
behaviour::NetworkBehaviour,
|
||||||
|
@ -122,11 +120,11 @@ mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
struct RuntimeRecord {
|
struct RuntimeRecord<T> {
|
||||||
states: HashMap<NodeId, View>,
|
states: HashMap<NodeId, T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T: Serialize> TryFrom<&SimulationState<S, T>> for RuntimeRecord {
|
impl<S, T: Serialize + Clone> TryFrom<&SimulationState<S, T>> for RuntimeRecord<T> {
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn try_from(value: &SimulationState<S, T>) -> Result<Self, Self::Error> {
|
fn try_from(value: &SimulationState<S, T>) -> Result<Self, Self::Error> {
|
||||||
|
@ -135,7 +133,7 @@ mod tests {
|
||||||
.nodes
|
.nodes
|
||||||
.read()
|
.read()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|node| (node.id(), node.current_view()))
|
.map(|node| (node.id(), node.state().clone()))
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,9 +102,7 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::{collections::HashMap, time::Duration};
|
use std::time::Duration;
|
||||||
|
|
||||||
type View = usize;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
network::{
|
network::{
|
||||||
|
|
Loading…
Reference in New Issue