cleanup.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //! Tests to ensure that documents are garbage collected.
  2. use std::time::Duration;
  3. use anyhow::Result;
  4. use common::*;
  5. use operational_transform::OperationSeq;
  6. use rustpad_server::{server, ServerConfig};
  7. use serde_json::json;
  8. use tokio::time;
  9. pub mod common;
  10. #[tokio::test]
  11. async fn test_cleanup() -> Result<()> {
  12. pretty_env_logger::try_init().ok();
  13. let filter = server(ServerConfig {
  14. expiry_days: 2,
  15. ..ServerConfig::default()
  16. });
  17. expect_text(&filter, "old", "").await;
  18. let mut client = connect(&filter, "old").await?;
  19. let msg = client.recv().await?;
  20. assert_eq!(msg, json!({ "Identity": 0 }));
  21. let mut operation = OperationSeq::default();
  22. operation.insert("hello");
  23. let msg = json!({
  24. "Edit": {
  25. "revision": 0,
  26. "operation": operation
  27. }
  28. });
  29. client.send(&msg).await;
  30. let msg = client.recv().await?;
  31. msg.get("History")
  32. .expect("should receive history operation");
  33. expect_text(&filter, "old", "hello").await;
  34. let hour = Duration::from_secs(3600);
  35. time::pause();
  36. time::advance(47 * hour).await;
  37. expect_text(&filter, "old", "hello").await;
  38. time::advance(3 * hour).await;
  39. expect_text(&filter, "old", "").await;
  40. Ok(())
  41. }