Skip to content

Commit

Permalink
Fix gateway and botlink fields, update locks (#208)
Browse files Browse the repository at this point in the history
* Gateway: Fix test, fix websocket field, update lock

* Update tinybrain lock

* Fix botlink, update lock
  • Loading branch information
Terkwood authored Apr 5, 2020
1 parent 0d0bd72 commit 2bf8df9
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 486 deletions.
65 changes: 33 additions & 32 deletions botlink/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion botlink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "botlink"
version = "0.0.1"
version = "0.0.2"
authors = ["terkwood <38859656+Terkwood@users.noreply.github.com>"]
edition = "2018"

Expand Down
29 changes: 24 additions & 5 deletions botlink/src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ pub fn process(opts: &mut StreamOpts) {
Ok(xrr) => {
for time_ordered_event in xrr {
match time_ordered_event {
(entry_id, StreamData::AB(AttachBot { game_id, player })) => {
(
entry_id,
StreamData::AB(AttachBot {
game_id,
player,
board_size,
}),
) => {
if let Err(e) = opts.attached_bots_repo.attach(&game_id, player) {
error!("Error attaching bot {:?}", e)
} else {
Expand All @@ -30,9 +37,13 @@ pub fn process(opts: &mut StreamOpts) {
{
error!("Error saving entry ID for attach bot {:?}", e)
} else {
if let Err(e) = opts
.xadder
.xadd_game_state(game_id, GameState::default())
let mut game_state = GameState::default();
if let Some(bs) = board_size {
game_state.board.size = bs.into()
}

if let Err(e) =
opts.xadder.xadd_game_state(game_id, game_state)
{
error!("Error writing redis stream for game state changelog : {:?}",e)
}
Expand Down Expand Up @@ -190,6 +201,7 @@ mod tests {
struct FakeXReader {
game_id: GameId,
player: Player,
board_size: Option<u8>,
incoming_game_state: Arc<Mutex<Option<(XReadEntryId, StreamData)>>>,
}
impl xread::XReader for FakeXReader {
Expand All @@ -202,12 +214,17 @@ mod tests {
> {
let game_id = self.game_id.clone();
let player = self.player;
let board_size = self.board_size;
let mut v: Vec<(XReadEntryId, StreamData)> = vec![(
XReadEntryId {
millis_time: 10,
seq_no: 0,
},
StreamData::AB(AttachBot { game_id, player }),
StreamData::AB(AttachBot {
game_id,
player,
board_size,
}),
)];
if let Some((inc_eid, inc_game_state)) =
self.incoming_game_state.lock().expect("xrl").clone()
Expand Down Expand Up @@ -244,10 +261,12 @@ mod tests {

const GAME_ID: GameId = GameId(Uuid::nil());
let player = Player::WHITE;
let board_size = Some(13);
let incoming_game_state = Arc::new(Mutex::new(None));
let xreader = Box::new(FakeXReader {
game_id: GAME_ID.clone(),
player,
board_size,
incoming_game_state: incoming_game_state.clone(),
});
let xadder = Box::new(FakeXAdder { added_in });
Expand Down
Loading

0 comments on commit 2bf8df9

Please sign in to comment.