()
| 67 | |
| 68 | #[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 69 | async fn test_housekeeping_db_closed() { |
| 70 | let t = TestContext::new().await; |
| 71 | |
| 72 | let avatar_src = t.dir.path().join("avatar.png"); |
| 73 | let avatar_bytes = include_bytes!("../../test-data/image/avatar64x64.png"); |
| 74 | tokio::fs::write(&avatar_src, avatar_bytes).await.unwrap(); |
| 75 | t.set_config(Config::Selfavatar, Some(avatar_src.to_str().unwrap())) |
| 76 | .await |
| 77 | .unwrap(); |
| 78 | |
| 79 | let event_source = t.get_event_emitter(); |
| 80 | |
| 81 | let a = t.get_config(Config::Selfavatar).await.unwrap().unwrap(); |
| 82 | assert_eq!(avatar_bytes, &tokio::fs::read(&a).await.unwrap()[..]); |
| 83 | |
| 84 | t.sql.close().await; |
| 85 | housekeeping(&t).await.unwrap(); // housekeeping should emit warnings but not fail |
| 86 | t.sql.open(&t, "".to_string()).await.unwrap(); |
| 87 | |
| 88 | let a = t.get_config(Config::Selfavatar).await.unwrap().unwrap(); |
| 89 | assert_eq!(avatar_bytes, &tokio::fs::read(&a).await.unwrap()[..]); |
| 90 | |
| 91 | while let Ok(event) = event_source.try_recv() { |
| 92 | match event.typ { |
| 93 | EventType::Info(s) => assert!( |
| 94 | !s.contains("Keeping new unreferenced file"), |
| 95 | "File {s} was almost deleted, only reason it was kept is that it was created recently (as the tests don't run for a long time)" |
| 96 | ), |
| 97 | EventType::Error(s) => panic!("{}", s), |
| 98 | _ => {} |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /// Regression test for a bug where housekeeping deleted drafts since their |
| 104 | /// `hidden` flag is set. |
nothing calls this directly
no test coverage detected