Fix historical pagination and bound export and proxy memory
This commit is contained in:
@@ -98,6 +98,47 @@ def test_mysql_reuses_negotiated_tls_context_between_connections(mysql, monkeypa
|
||||
assert creations == []
|
||||
|
||||
|
||||
def test_mysql_bounded_catalog_and_history_targets_preserve_filters(mysql):
|
||||
mysql.upsert_catalog(normalize_catalog(raw_catalog(), 2027))
|
||||
mysql.upsert_catalog(normalize_catalog(raw_catalog(), 2026))
|
||||
scores = select_score_lines([{'code': '081200', 'total': 310, 'depart_name': '计算机学院'}], '081200', '10001', '北京大学', 2026)
|
||||
mysql.upsert_scores(scores)
|
||||
targets = list(mysql.score_targets({'year': 2027, 'provinces': ['北京']}, batch_size=1))
|
||||
assert len(targets) == 1
|
||||
assert targets[0]['major_code'] == '081200'
|
||||
assert 'data' not in targets[0]
|
||||
rows = list(mysql.iter_catalog({'year': 2027}, batch_size=1))
|
||||
assert len(rows) == 2
|
||||
assert len(list(mysql.iter_catalog({'year': 2026, 'max_score': 310}, batch_size=1))) == 2
|
||||
assert len(list(mysql.iter_scores({('10001', '081200')}, batch_size=1))) == 1
|
||||
|
||||
|
||||
def test_mysql_unit_commit_is_atomic_and_idempotent(mysql):
|
||||
mysql.job_create('atomic-job', {})
|
||||
rows = normalize_catalog(raw_catalog(), 2027)
|
||||
scores = select_score_lines([{'code': '081200', 'total': 310}], '081200', '10001', '北京大学', 2026)
|
||||
assert mysql.save_unit('atomic-job', 'catalog:test', rows, scores=scores)
|
||||
assert not mysql.save_unit('atomic-job', 'catalog:test', rows, scores=scores)
|
||||
assert mysql.job_get('atomic-job')['records'] == 2
|
||||
assert mysql.job_get('atomic-job')['completed_units'] == 1
|
||||
assert mysql.overview()['records'] == 2
|
||||
assert mysql.overview()['scores'] == 1
|
||||
|
||||
|
||||
def test_mysql_failed_unit_rolls_back_every_write(mysql, monkeypatch):
|
||||
mysql.job_create('atomic-job', {})
|
||||
def fail(*args):
|
||||
raise RuntimeError('interrupted unit')
|
||||
monkeypatch.setattr(mysql, '_school', fail)
|
||||
rows = normalize_catalog(raw_catalog(), 2027)
|
||||
scores = select_score_lines([{'code': '081200', 'total': 310}], '081200', '10001', '北京大学', 2026)
|
||||
with pytest.raises(RuntimeError):
|
||||
mysql.save_unit('atomic-job', 'catalog:test', rows, scores=scores)
|
||||
assert mysql.job_get('atomic-job')['records'] == 0
|
||||
assert mysql.job_get('atomic-job')['completed_units'] == 0
|
||||
assert mysql.overview()['records'] == mysql.overview()['scores'] == 0
|
||||
|
||||
|
||||
def test_sqlite_migration_preserves_ids_and_refuses_nonempty_target(mysql, tmp_path):
|
||||
from studio.migrate import migrate_sqlite
|
||||
source = Database(tmp_path / 'snapshot.db')
|
||||
|
||||
Reference in New Issue
Block a user