Files
servo/components/storage/tests/storage_thread.rs
Taym Haddadi 628c9c1170 storage: construct and shut down public/private thread groups independently (#43147)
This PR makes public and private storage thread groups independent.

previously, `new_storage_threads()` returned two `StorageThreads`
handles, but both handles were backed by the same underlying storage
worker group. this meant Servo carried a public/private distinction
through the API and wiring layers, while both sides still talked to the
same storage backend threads.


Testing: Added shutdown_storage_group test, and should not effect WTP
test.

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2026-03-13 10:03:30 +00:00

51 lines
2.0 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::generic_channel::{self, GenericSend};
use profile::mem as profile_mem;
use storage_traits::StorageThreads;
use storage_traits::client_storage::ClientStorageThreadMessage;
use storage_traits::indexeddb::{IndexedDBThreadMsg, SyncOperation};
use storage_traits::webstorage_thread::WebStorageThreadMsg;
fn shutdown_storage_group(threads: &StorageThreads) {
let (client_sender, client_receiver) = generic_channel::channel().unwrap();
GenericSend::send(threads, ClientStorageThreadMessage::Exit(client_sender))
.expect("failed to send client storage exit");
client_receiver
.recv()
.expect("failed to receive client storage exit ack");
let (idb_sender, idb_receiver) = generic_channel::channel().unwrap();
GenericSend::send(
threads,
IndexedDBThreadMsg::Sync(SyncOperation::Exit(idb_sender)),
)
.expect("failed to send indexeddb exit");
idb_receiver
.recv()
.expect("failed to receive indexeddb exit ack");
let (web_storage_sender, web_storage_receiver) = generic_channel::channel().unwrap();
GenericSend::send(threads, WebStorageThreadMsg::Exit(web_storage_sender))
.expect("failed to send web storage exit");
web_storage_receiver
.recv()
.expect("failed to receive web storage exit ack");
}
#[test]
fn test_new_storage_threads_create_independent_groups() {
let mem_profiler_chan = profile_mem::Profiler::create();
let (private_storage_threads, public_storage_threads) =
storage::new_storage_threads(mem_profiler_chan, None);
shutdown_storage_group(&private_storage_threads);
shutdown_storage_group(&public_storage_threads);
// Workaround for https://github.com/servo/servo/issues/32912
#[cfg(windows)]
std::thread::sleep(std::time::Duration::from_millis(1000));
}