nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

integration_test.rs (1415B)


      1 use anyhow::Result;
      2 
      3 use std::thread;
      4 use std::time::Duration;
      5 
      6 mod common;
      7 
      8 #[tokio::test]
      9 async fn start_and_stop() -> Result<()> {
     10     // this will be the common pattern for acquiring a new relay:
     11     // start a fresh relay, on a port to-be-provided back to us:
     12     let relay = common::start_relay()?;
     13     // wait for the relay's webserver to start up and deliver a page:
     14     common::wait_for_healthy_relay(&relay).await?;
     15     let port = relay.port;
     16     // just make sure we can startup and shut down.
     17     // if we send a shutdown message before the server is listening,
     18     // we will get a SendError.  Keep sending until someone is
     19     // listening.
     20     loop {
     21         let shutdown_res = relay.shutdown_tx.send(());
     22         match shutdown_res {
     23             Ok(()) => {
     24                 break;
     25             }
     26             Err(_) => {
     27                 thread::sleep(Duration::from_millis(100));
     28             }
     29         }
     30     }
     31     // wait for relay to shutdown
     32     let thread_join = relay.handle.join();
     33     assert!(thread_join.is_ok());
     34     // assert that port is now available.
     35     assert!(common::port_is_available(port));
     36     Ok(())
     37 }
     38 
     39 #[tokio::test]
     40 async fn relay_home_page() -> Result<()> {
     41     // get a relay and wait for startup...
     42     let relay = common::start_relay()?;
     43     common::wait_for_healthy_relay(&relay).await?;
     44     // tell relay to shutdown
     45     let _res = relay.shutdown_tx.send(());
     46     Ok(())
     47 }