зеркало из https://github.com/openwpm/OpenWPM.git
Reenabling extension tests (#929)
* Fixed and enabled extension tests * Narrowed types for display_mode * Updated package-lock.json * Removed storage.rst
This commit is contained in:
Родитель
613e7d6633
Коммит
2cb831fac5
|
@ -48,7 +48,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
test-groups: ["test/test_[a-e]*", "test/test_[f-h]*", "test/test_[i-o,q-r,t-z]*", "test/test_[p]*", "test/test_[s]*", "test/storage/*"]
|
||||
test-groups: ["test/test_[a-e]*", "test/test_[f-h]*", "test/test_[i-o,q-r,t-z]*", "test/test_[p]*", "test/test_[s]*", "test/storage/*", "test/extension/*"]
|
||||
fail-fast: false
|
||||
steps:
|
||||
# All of these steps are just setup, maybe we should wrap them in an action
|
||||
|
|
|
@ -4,9 +4,10 @@ import os
|
|||
import signal
|
||||
import sys
|
||||
import time
|
||||
import typing
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
from typing import Any, Callable, List
|
||||
from typing import Any, Callable, List, Literal
|
||||
|
||||
import sentry_sdk
|
||||
|
||||
|
@ -36,6 +37,8 @@ AUTH_TOKEN = os.getenv("GCP_AUTH_TOKEN", "cloud")
|
|||
|
||||
# Browser Params
|
||||
DISPLAY_MODE = os.getenv("DISPLAY_MODE", "headless")
|
||||
assert DISPLAY_MODE in ["headless", "xvfb", "native"]
|
||||
DISPLAY_MODE = typing.cast(Literal["headless", "xvfb", "native"], DISPLAY_MODE)
|
||||
HTTP_INSTRUMENT = os.getenv("HTTP_INSTRUMENT", "1") == "1"
|
||||
COOKIE_INSTRUMENT = os.getenv("COOKIE_INSTRUMENT", "1") == "1"
|
||||
NAVIGATION_INSTRUMENT = os.getenv("NAVIGATION_INSTRUMENT", "1") == "1"
|
||||
|
|
|
@ -70,7 +70,7 @@ export let open = async function(storageControllerAddress, logAddress, curr_craw
|
|||
// Listen for incoming urls as visit ids
|
||||
listeningSocket = new socket.ListeningSocket(listeningSocketCallback);
|
||||
console.log("Starting socket listening for incoming connections.");
|
||||
listeningSocket.startListening().then(() => {
|
||||
await listeningSocket.startListening().then(() => {
|
||||
browser.profileDirIO.writeFile("extension_port.txt", `${listeningSocket.port}`);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
from dataclasses import dataclass, field
|
||||
from json import JSONEncoder
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
|
||||
|
||||
from dataclasses_json import DataClassJsonMixin
|
||||
from dataclasses_json import config as DCJConfig
|
||||
|
@ -92,7 +92,7 @@ class BrowserParams(DataClassJsonMixin):
|
|||
seed_tar: Optional[Path] = field(
|
||||
default=None, metadata=DCJConfig(encoder=path_to_str, decoder=str_to_path)
|
||||
)
|
||||
display_mode: str = "native"
|
||||
display_mode: Literal["native", "headless", "xvfb"] = "native"
|
||||
browser: str = "firefox"
|
||||
prefs: dict = field(default_factory=dict)
|
||||
tp_cookies: str = "always"
|
||||
|
|
|
@ -89,7 +89,6 @@ class TaskManager:
|
|||
if not os.path.exists(manager_params.source_dump_path):
|
||||
os.makedirs(manager_params.source_dump_path)
|
||||
|
||||
# Check size of parameter dictionary
|
||||
self.num_browsers = manager_params.num_browsers
|
||||
|
||||
# Parse and flesh out js_instrument_settings
|
||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
|||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Generator, List, Tuple
|
||||
from typing import Any, Callable, Generator, List, Literal, Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -93,13 +93,13 @@ def task_manager_creator(
|
|||
@pytest.fixture()
|
||||
def http_params(
|
||||
default_params: Tuple[ManagerParams, List[BrowserParams]],
|
||||
) -> Callable[[str], Tuple[ManagerParams, List[BrowserParams]]]:
|
||||
) -> Callable[[Literal["headless", "xvfb"]], Tuple[ManagerParams, List[BrowserParams]]]:
|
||||
manager_params, browser_params = default_params
|
||||
for browser_param in browser_params:
|
||||
browser_param.http_instrument = True
|
||||
|
||||
def parameterize(
|
||||
display_mode: str = "headless",
|
||||
display_mode: Literal["headless", "xvfb"] = "headless",
|
||||
) -> Tuple[ManagerParams, List[BrowserParams]]:
|
||||
for browser_param in browser_params:
|
||||
browser_param.display_mode = display_mode
|
||||
|
|
|
@ -19,4 +19,4 @@ def test_extension_logging(task_manager_creator, default_params, tmp_path):
|
|||
if test_msg in log_line:
|
||||
log_list.append(log_line)
|
||||
# We expect to see it once when printing the config and once when printing the log message
|
||||
assert len(log_line) == 2 * manager_params.num_browsers
|
||||
assert len(log_list) == 2 * manager_params.num_browsers
|
||||
|
|
|
@ -10,14 +10,10 @@ def test_extension_startup_timeout(task_manager_creator, default_params):
|
|||
browser_param.custom_params[
|
||||
"pre_instrumentation_code"
|
||||
] = """
|
||||
(async () => {
|
||||
const myPromise = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 20000); // Delaying for 20 seconds
|
||||
});
|
||||
await myPromise;
|
||||
})()
|
||||
const startTime = Date.now();
|
||||
while (Date.now() - startTime < 20000) { // Delaying for 20s
|
||||
console.log("delaying startup");
|
||||
};
|
||||
"""
|
||||
with pytest.raises(BrowserConfigError) as error:
|
||||
tm, _ = task_manager_creator((manager_params, browser_params[:1]))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from pathlib import Path
|
||||
from typing import List, Optional, Tuple
|
||||
from typing import List, Literal, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -51,7 +51,7 @@ class OpenWPMTest:
|
|||
self,
|
||||
data_dir: Optional[Path] = None,
|
||||
num_browsers: int = NUM_BROWSERS,
|
||||
display_mode: str = "headless",
|
||||
display_mode: Literal["headless", "xvfb"] = "headless",
|
||||
) -> Tuple[ManagerParams, List[BrowserParams]]:
|
||||
"""Load and return the default test parameters."""
|
||||
if not data_dir:
|
||||
|
|
|
@ -822,14 +822,10 @@ def test_page_visit(task_manager_creator, http_params, delayed):
|
|||
browser_param.custom_params[
|
||||
"pre_instrumentation_code"
|
||||
] = """
|
||||
(async () => {
|
||||
const myPromise = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 5000); // Delaying for 5 seconds
|
||||
});
|
||||
await myPromise;
|
||||
})()
|
||||
const startTime = Date.now();
|
||||
while (Date.now() - startTime < 5000) { // Delaying for 5s
|
||||
console.log("delaying startup");
|
||||
};
|
||||
"""
|
||||
|
||||
tm, db = task_manager_creator((manager_params, browser_params))
|
||||
|
|
Загрузка…
Ссылка в новой задаче