Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat: treat end-of-events as end, not as an error
Lars Wirzenius committed 1 year ago
commit 14e2eaec015bf62f9b3472c6552aa3d5a20e3bdc
parent ad807720336ae92c385db6acf50ab44d27796d68
3 files changed +21 -39
modified ci-broker.md
@@ -232,10 +232,9 @@ when I run bash radenv.sh bash setup-node.sh

given an installed synthetic-events
given file refsfetched.json
-
given file shutdown.json
given file set-rid
when I run env HOME=../homedir python3 set-rid refsfetched.json testy
-
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log log.txt
+
when I run synthetic-events synt.sock refsfetched.json --log log.txt

given an installed cib
given a directory reports
@@ -245,9 +244,9 @@ when I run chmod +x adapter.sh

when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
then command is successful
-
when I run cibtool --db ci-broker.db event shutdown

given an installed cibtool
+
when I run cibtool --db ci-broker.db event shutdown
when I run cibtool --db ci-broker.db event list
when I run cibtool --db ci-broker.db run list

@@ -281,10 +280,9 @@ when I run bash radenv.sh bash setup-node.sh

given an installed synthetic-events
given file refsfetched.json
-
given file shutdown.json
given file set-rid
when I run env HOME=../homedir python3 set-rid refsfetched.json testy
-
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log log.txt
+
when I run synthetic-events synt.sock refsfetched.json --log log.txt

given file adapter.sh from adapter-with-url.sh
when I run chmod +x adapter.sh
@@ -383,7 +381,7 @@ given an installed synthetic-events
when I run synthetic-events synt.sock --log log.txt
given file broker.yaml
when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
-
then stderr contains "connection to the node control socket broke"
+
then command is successful
~~~


@@ -409,11 +407,13 @@ when I run bash radenv.sh bash setup-node.sh

given an installed cib
given an installed synthetic-events
-
given file shutdown.json
given file broker.yaml
-
when I run synthetic-events synt.sock shutdown.json --log synt.log
+
when I run synthetic-events synt.sock --log synt.log
when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
+
when I run cat synt.log
then command is successful
+
when I run cibtool --db ci-broker.db run list
+
then stdout is exactly ""
~~~


@@ -574,8 +574,7 @@ given an installed cib
given an installed synthetic-events

given file refsfetched.json
-
given file shutdown.json
-
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log synt.log
+
when I run synthetic-events synt.sock refsfetched.json --log synt.log

given file broker.yaml
when I try to run bash radenv.sh env RAD_SOCKET=synt.sock cib --config broker.yaml insert
@@ -604,8 +603,7 @@ given an installed cib
given an installed synthetic-events

given file refsfetched.json
-
given file shutdown.json
-
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log synt.log --repeat 1000
+
when I run synthetic-events synt.sock refsfetched.json --log synt.log --repeat 1000

given file broker.yaml
when I try to run bash radenv.sh env RAD_SOCKET=synt.sock cib --config broker.yaml insert
@@ -635,8 +633,7 @@ given an installed cib
given an installed synthetic-events

given file refsfetched.json
-
given file shutdown.json
-
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log synt.log
+
when I run synthetic-events synt.sock refsfetched.json --log synt.log

given file broker.yaml from broker-allow-nothing.yaml
when I try to run bash radenv.sh env RAD_SOCKET=synt.sock cib --config broker.yaml insert
modified src/event.rs
@@ -111,10 +111,6 @@ impl NodeEventSource {
            if let Some(event) = self.events.next() {
                trace!("got event from local node: {event:#?}");
                match event {
-
                    Ok(ref event) if Self::is_shutdown_request(event) => {
-
                        info!("got shutdown request from node control socket");
-
                        return Ok(vec![BrokerEvent::shutdown()]);
-
                    }
                    Ok(event) => {
                        trace!("got node event {:#?}", event);
                        let mut result = vec![];
@@ -140,20 +136,9 @@ impl NodeEventSource {
                }
            } else {
                trace!("no more node events from control socket: iterator ended");
-
                return Err(NodeEventError::BrokenConnection);
-
            }
-
        }
-
    }
-

-
    fn is_shutdown_request(event: &Event) -> bool {
-
        if let Event::RefsFetched { updated, .. } = event {
-
            if let Some(RefUpdate::Skipped { name, .. }) = updated.first() {
-
                if name == &RefString::try_from("shutdown").expect("create name") {
-
                    return true;
-
                }
+
                return Ok(vec![]);
            }
        }
-
        false
    }
}

modified src/queueadd.rs
@@ -6,7 +6,7 @@ use log::{debug, info};

use crate::{
    db::{Db, DbError},
-
    event::{BrokerEvent, EventFilter, NodeEventError, NodeEventSource},
+
    event::{EventFilter, NodeEventError, NodeEventSource},
};

#[derive(Default)]
@@ -60,14 +60,14 @@ impl QueueAdder {
        // event from the node.
        'event_loop: loop {
            debug!("waiting for event from node");
-
            for e in source.event()? {
-
                debug!("got event {e:#?}");
-
                match e {
-
                    BrokerEvent::Shutdown => break 'event_loop,
-
                    BrokerEvent::RefChanged { .. } => {
-
                        info!("insert broker event into queue: {e:#?}");
-
                        self.db.push_queued_event(e)?;
-
                    }
+
            let events = source.event()?;
+
            if events.is_empty() {
+
                break 'event_loop;
+
            } else {
+
                for e in events {
+
                    debug!("got event {e:#?}");
+
                    info!("insert broker event into queue: {e:#?}");
+
                    self.db.push_queued_event(e)?;
                }
            }
        }