Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
5b18d781
Commit
5b18d781
authored
Mar 17, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
3356c294
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
11 deletions
+30
-11
go/zodb/storage/demo/demo.go
go/zodb/storage/demo/demo.go
+10
-0
go/zodb/storage/demo/demo_test.go
go/zodb/storage/demo/demo_test.go
+20
-11
No files found.
go/zodb/storage/demo/demo.go
View file @
5b18d781
...
...
@@ -46,6 +46,16 @@ type Storage struct {
baseAt0
zodb
.
Tid
}
// baseMutatedError is reported when Storage.base is detected to change.
type
baseMutatedError
struct
{
baseAt0
zodb
.
Tid
baseHead
zodb
.
Tid
}
func
(
e
*
baseMutatedError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"base.head mutated from @%s to @%s"
,
e
.
baseAt0
,
e
.
baseHead
)
}
// Close implements zodb.IStorageDriver .
func
(
d
*
Storage
)
Close
()
(
err
error
)
{
...
...
go/zodb/storage/demo/demo_test.go
View file @
5b18d781
...
...
@@ -26,6 +26,7 @@ import (
"fmt"
"net/url"
"os"
"reflect"
"regexp"
"testing"
...
...
@@ -170,11 +171,11 @@ func TestWatch(t *testing.T) {
}
// MutateBase mutates ddat.base with new commit.
func
(
ddat
*
DemoData
)
MutateBase
()
error
{
_
,
err
=
xtesting
.
ZPyCommitRaw
(
ddat
.
base
,
0
,
xtesting
.
ZRawObject
{
func
(
ddat
*
DemoData
)
MutateBase
()
(
zodb
.
Tid
,
error
)
{
return
xtesting
.
ZPyCommitRaw
(
ddat
.
base
,
0
,
xtesting
.
ZRawObject
{
Oid
:
1
,
Data
:
[]
byte
(
"ZZZ"
),
})
;
X
(
err
)
})
}
// TestSync_vs_BaseMutate verifies Sync wrt base mutation.
...
...
@@ -187,10 +188,13 @@ func TestSync_vs_BaseMutate(t *testing.T) {
t
.
Fatalf
(
"sync0: head=%s err=%s"
,
head
,
err
)
}
err
=
ddat
.
MutateBase
();
X
(
err
)
tid
,
err
:
=
ddat
.
MutateBase
();
X
(
err
)
head
,
err
:=
ddrv
.
Sync
(
context
.
Background
())
errOk
:=
&
zodb
.
OpError
{
URL
:
ddrv
.
URL
(),
Op
:
"sync"
,
Err
:
...
}
head
,
err
=
ddrv
.
Sync
(
context
.
Background
())
errOk
:=
&
zodb
.
OpError
{
URL
:
ddrv
.
URL
(),
Op
:
"sync"
,
Err
:
&
baseMutatedError
{
baseAt0
:
0
,
baseHead
:
tid
,
}}
if
!
reflect
.
DeepEqual
(
err
,
errOk
)
{
t
.
Fatalf
(
"after base mutate: sync: unexpected error:
\n
have: %s
\n
want: %s"
,
err
,
errOk
)
...
...
@@ -204,12 +208,12 @@ func TestWatchLoad_vs_BaseMutate(t *testing.T) {
X
:=
xtesting
.
FatalIf
(
t
)
watchq
:=
make
(
chan
zodb
.
Event
)
ddrv
,
at0
,
err
=
demoOpen
(
ddat
.
URL
(),
&
zodb
.
DriverOptions
{
ddrv
,
at0
,
err
:
=
demoOpen
(
ddat
.
URL
(),
&
zodb
.
DriverOptions
{
ReadOnly
:
true
,
Watchq
:
watchq
,
});
X
(
err
)
err
=
ddat
.
MutateBase
();
X
(
err
)
tid
,
err
:
=
ddat
.
MutateBase
();
X
(
err
)
// first wait for error from watchq
event
:=
<-
watchq
...
...
@@ -218,15 +222,20 @@ func TestWatchLoad_vs_BaseMutate(t *testing.T) {
t
.
Fatalf
(
"unexpected event: %T"
,
event
)
}
evErrOk
:=
&
zodb
.
EventError
{
Err
:
...
}
// XXX
errBaseMutated
:=
&
baseMutatedError
{
baseAt0
:
0
,
baseHead
:
tid
,
}
evErrOk
:=
&
zodb
.
EventError
{
Err
:
errBaseMutated
}
if
!
reflect
.
DeepEqual
(
evErr
,
evErrOk
)
{
t
.
Fatalf
(
"after base mutate: unexpected event:
\n
have: %s
\n
want: %s"
,
evErr
,
evErrOk
)
}
// now make sure Load fails with "base mutated" error
xid
:=
zodb
.
Xid
{
Oid
:
1
,
At
:
zodb
.
MaxTid
}
xid
:=
zodb
.
Xid
{
Oid
:
1
,
At
:
at0
}
data
,
serial
,
err
:=
ddrv
.
Load
(
context
.
Background
(),
xid
)
errOk
:=
&
zodb
.
OpError
{
URL
:
ddrv
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
...
}
errOk
:=
&
zodb
.
OpError
{
URL
:
ddrv
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
errBaseMutated
}
if
!
reflect
.
DeepEqual
(
err
,
errOk
)
{
t
.
Fatalf
(
"after base mutate: load: unexpected error:
\n
have: %s
\n
want: %s"
,
err
,
errOk
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment