Avoid double borrow in tests by drawing windows explicitly in `flush_effects`

Max Brunsfeld and Antonio created

Co-authored-by: Antonio <antonio@zed.dev>

Change summary

crates/gpui2/src/app.rs                  | 15 ++++++++++++++-
crates/gpui2/src/platform/test/window.rs |  2 +-
crates/gpui2/src/window.rs               |  2 +-
3 files changed, 16 insertions(+), 3 deletions(-)

Detailed changes

crates/gpui2/src/app.rs 🔗

@@ -596,13 +596,26 @@ impl AppContext {
             }
         }
 
-        for (_, window) in &self.windows {
+        for window in self.windows.values() {
             if let Some(window) = window.as_ref() {
                 if window.dirty {
                     window.platform_window.invalidate();
                 }
             }
         }
+
+        #[cfg(any(test, feature = "test-support"))]
+        for window in self
+            .windows
+            .values()
+            .filter_map(|window| {
+                let window = window.as_ref()?;
+                window.dirty.then_some(window.handle)
+            })
+            .collect::<Vec<_>>()
+        {
+            self.update_window(window, |_, cx| cx.draw()).ok();
+        }
     }
 
     /// Repeatedly called during `flush_effects` to release any entities whose

crates/gpui2/src/platform/test/window.rs 🔗

@@ -168,7 +168,7 @@ impl PlatformWindow for TestWindow {
     }
 
     fn invalidate(&self) {
-        (self.draw.lock())().unwrap();
+        // (self.draw.lock())().unwrap();
     }
 
     fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {

crates/gpui2/src/window.rs 🔗

@@ -1181,7 +1181,7 @@ impl<'a> WindowContext<'a> {
     }
 
     /// Draw pixels to the display for this window based on the contents of its scene.
-    fn draw(&mut self) -> Scene {
+    pub(crate) fn draw(&mut self) -> Scene {
         self.text_system().start_frame();
         self.window.platform_window.clear_input_handler();
         self.window.layout_engine.as_mut().unwrap().clear();