test: 租约开关隔离(XBCR_DISABLE_LEASES),避免跨进程租约把单测拦掉
- db.acquire_lease 支持 XBCR_DISABLE_LEASES=1 直接放行(仅测试用) - test_order_sync 设置该开关;test_leases 在自己的 setUp 里临时关闭并恢复 - 顺手把 map.js 的自动拆分实验回滚(脚本按缩进切函数不安全, 函数在文件里的括号深度不一致,容易切坏),保留已验证的 src/core/geo.js
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""跨进程租约(多 worker 选主 / 单任务抢占)。"""
|
||||
import os
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -10,6 +11,8 @@ import db
|
||||
|
||||
class LeaseTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# 其它用例会设 XBCR_DISABLE_LEASES 让租约直接放行;这里要真测租约
|
||||
self._old_flag = os.environ.pop("XBCR_DISABLE_LEASES", None)
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.path = Path(self.tmp.name) / "lease.db"
|
||||
self._old = db.DB_PATH
|
||||
@@ -18,6 +21,8 @@ class LeaseTests(unittest.TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
db.DB_PATH = self._old
|
||||
if self._old_flag is not None:
|
||||
os.environ["XBCR_DISABLE_LEASES"] = self._old_flag
|
||||
self.tmp.cleanup()
|
||||
|
||||
def test_first_acquire_wins_and_second_is_blocked_for_other_owner(self):
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import unittest
|
||||
import os
|
||||
|
||||
os.environ["XBCR_DISABLE_LEASES"] = "1" # 单测不参与跨进程租约
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
Reference in New Issue
Block a user