Commit f117335c authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: Fix Persistent.badf

Due to forgotten ... it was not passing prepared argv as argv to
fmt.Errorf, but as a single slice argument. The result was messy, for
example

    persistent_test.go:176: deactivate refcnt < 0: panic error unexpected:
        have: "[t.zodb.MyObject 000000000000000c](%!s(MISSING)): deactivate: refcnt < 0"
        want: "t.zodb.MyObject(000000000000000c): deactivate: refcnt < 0"

Using the occasion add details to deactivate refcnt panic, which
made me to discover this bug.
parent 475647e2
......@@ -246,7 +246,7 @@ func (obj *Persistent) PDeactivate() {
obj.refcnt--
if obj.refcnt < 0 {
panic(obj.badf("deactivate: refcnt < 0"))
panic(obj.badf("deactivate: refcnt < 0 (= %d)", obj.refcnt))
}
if obj.refcnt > 0 {
return // users still left
......@@ -310,7 +310,7 @@ func (obj *Persistent) istate() Ghostable {
// badf returns formatted error prefixed with obj's class and oid.
func (obj *Persistent) badf(format string, argv ...interface{}) error {
return fmt.Errorf("%s(%s): "+format,
append([]interface{}{obj.zclass.class, obj.oid}, argv...))
append([]interface{}{obj.zclass.class, obj.oid}, argv...)...)
}
......
......@@ -163,6 +163,22 @@ func TestPersistent(t *testing.T) {
obj2 := &Unregistered{}
assert.Equal(ClassOf(obj2), `ZODB.Go("lab.nexedi.com/kirr/neo/go/zodb.Unregistered")`)
// deactivate refcnt < 0 -> panic
func() {
defer func() {
r := recover()
if r == nil {
t.Fatal("deactivate refcnt < 0: not panicked")
}
ehave := fmt.Sprintf("%s", r)
ewant := fmt.Sprintf("t.zodb.MyObject(%s): deactivate: refcnt < 0 (= -1)", Oid(12))
if ehave != ewant {
t.Fatalf("deactivate refcnt < 0: panic error unexpected:\nhave: %q\nwant: %q", ehave, ewant)
}
}()
obj.PDeactivate()
}()
// TODO activate - jar has to load, state changes
// TODO activate again - refcnt++
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment