mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-08 05:52:55 +00:00
## Problem `black` is slow sometimes, we can replace it with `ruff format` (a new feature in 0.1.2 [0]), which produces pretty similar to black style [1]. On my local machine (MacBook M1 Pro 16GB): ``` # `black` on main $ hyperfine "BLACK_CACHE_DIR=/dev/null poetry run black ." Benchmark 1: BLACK_CACHE_DIR=/dev/null poetry run black . Time (mean ± σ): 3.131 s ± 0.090 s [User: 5.194 s, System: 0.859 s] Range (min … max): 3.047 s … 3.354 s 10 runs ``` ``` # `ruff format` on the current PR $ hyperfine "RUFF_NO_CACHE=true poetry run ruff format" Benchmark 1: RUFF_NO_CACHE=true poetry run ruff format Time (mean ± σ): 300.7 ms ± 50.2 ms [User: 259.5 ms, System: 76.1 ms] Range (min … max): 267.5 ms … 420.2 ms 10 runs ``` ## Summary of changes - Replace `black` with `ruff format` everywhere - [0] https://docs.astral.sh/ruff/formatter/ - [1] https://docs.astral.sh/ruff/formatter/#black-compatibility
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
import pytest
|
|
from fixtures.log_helper import log
|
|
from fixtures.neon_fixtures import NeonEnvBuilder, WalCraft
|
|
|
|
# Restart nodes with WAL end having specially crafted shape, like last record
|
|
# crossing segment boundary, to test decoding issues.
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"wal_type",
|
|
[
|
|
"simple",
|
|
"last_wal_record_xlog_switch",
|
|
"last_wal_record_xlog_switch_ends_on_page_boundary",
|
|
"last_wal_record_crossing_segment",
|
|
"wal_record_crossing_segment_followed_by_small_one",
|
|
],
|
|
)
|
|
def test_crafted_wal_end(neon_env_builder: NeonEnvBuilder, wal_type: str):
|
|
env = neon_env_builder.init_start()
|
|
env.neon_cli.create_branch("test_crafted_wal_end")
|
|
|
|
endpoint = env.endpoints.create("test_crafted_wal_end")
|
|
wal_craft = WalCraft(env)
|
|
endpoint.config(wal_craft.postgres_config())
|
|
endpoint.start()
|
|
res = endpoint.safe_psql_many(
|
|
queries=[
|
|
"CREATE TABLE keys(key int primary key)",
|
|
"INSERT INTO keys SELECT generate_series(1, 100)",
|
|
"SELECT SUM(key) FROM keys",
|
|
]
|
|
)
|
|
assert res[-1][0] == (5050,)
|
|
|
|
wal_craft.in_existing(wal_type, endpoint.connstr())
|
|
|
|
log.info("Restarting all safekeepers and pageservers")
|
|
env.pageserver.stop()
|
|
env.safekeepers[0].stop()
|
|
env.safekeepers[0].start()
|
|
env.pageserver.start()
|
|
|
|
log.info("Trying more queries")
|
|
res = endpoint.safe_psql_many(
|
|
queries=[
|
|
"SELECT SUM(key) FROM keys",
|
|
"INSERT INTO keys SELECT generate_series(101, 200)",
|
|
"SELECT SUM(key) FROM keys",
|
|
]
|
|
)
|
|
assert res[0][0] == (5050,)
|
|
assert res[-1][0] == (20100,)
|
|
|
|
log.info("Restarting all safekeepers and pageservers (again)")
|
|
env.pageserver.stop()
|
|
env.safekeepers[0].stop()
|
|
env.safekeepers[0].start()
|
|
env.pageserver.start()
|
|
|
|
log.info("Trying more queries (again)")
|
|
res = endpoint.safe_psql_many(
|
|
queries=[
|
|
"SELECT SUM(key) FROM keys",
|
|
"INSERT INTO keys SELECT generate_series(201, 300)",
|
|
"SELECT SUM(key) FROM keys",
|
|
]
|
|
)
|
|
assert res[0][0] == (20100,)
|
|
assert res[-1][0] == (45150,)
|