fd71ea349e
build / build (push) Has been cancelled
共享业务栈与专用验收实例共用同一个 WeKnora 镜像,原来只按镜像判"未声明写入者", 任何一台开着共享栈的机器都永远开不了窗。判据改为:同项目或无项目标签即冲突; 另一个项目只有数据库/队列目标与源相同才算冲突。单测覆盖六种组合。
48 lines
2.2 KiB
Go
48 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// 同一台机器上可以有两套完全隔离的 WeKnora 栈共用同一个镜像(本机就是这样:
|
|
// 共享业务栈 + 专用验收实例)。只按镜像判断"未声明的写入者",会把另一套栈
|
|
// 当成并发写入者,验收链永远开不了窗;但只看项目标签又会放过多起一个
|
|
// 指向同一个库/队列的副本。判据要同时看归属与真实数据目标。
|
|
func TestUndeclaredWriterConflict(t *testing.T) {
|
|
source := map[string]string{
|
|
"DB_HOST": "kgmaint-postgres", "DB_NAME": "kgmaint_target", "DB_PORT": "5432",
|
|
"REDIS_ADDR": "kgmaint-redis:6379", "REDIS_NAMESPACE": "kgmaint",
|
|
}
|
|
cases := []struct {
|
|
name string
|
|
declared bool
|
|
project string
|
|
env map[string]string
|
|
want bool
|
|
reasonHint string
|
|
}{
|
|
{"已声明容器本身", true, "kgmaint-weknora", source, false, ""},
|
|
{"同项目里另起一份(不同名字)", false, "kgmaint-weknora", source, true, "同一 compose 项目"},
|
|
{"没有 compose 项目标签(docker run 的副本)", false, "", source, true, "没有 compose 项目标签"},
|
|
{"另一套隔离栈,数据目标不同", false, "weknora071full", map[string]string{
|
|
"DB_HOST": "WKNFull-postgres", "DB_NAME": "weknora_full", "REDIS_ADDR": "WKNFull-redis:6379", "REDIS_NAMESPACE": "weknora"},
|
|
false, ""},
|
|
{"另一套栈但指向同一个库", false, "other-project", map[string]string{
|
|
"DB_HOST": "kgmaint-postgres", "DB_NAME": "kgmaint_target", "REDIS_ADDR": "WKNFull-redis:6379"},
|
|
true, "同一个源数据库"},
|
|
{"另一套栈但共用同一队列", false, "other-project", map[string]string{
|
|
"DB_HOST": "other-pg", "DB_NAME": "other", "REDIS_ADDR": "kgmaint-redis:6379", "REDIS_NAMESPACE": "kgmaint"},
|
|
true, "同一个源队列"},
|
|
}
|
|
for _, tc := range cases {
|
|
conflict, reason := undeclaredWriterConflict(tc.declared, tc.project, "kgmaint-weknora", tc.env, source)
|
|
if conflict != tc.want {
|
|
t.Fatalf("%s: conflict=%v want %v (%s)", tc.name, conflict, tc.want, reason)
|
|
}
|
|
if tc.want && tc.reasonHint != "" && !strings.Contains(reason, tc.reasonHint) {
|
|
t.Fatalf("%s: reason %q should mention %q", tc.name, reason, tc.reasonHint)
|
|
}
|
|
}
|
|
}
|