Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
f8859a39
Commit
f8859a39
authored
Feb 19, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c6fb0b5f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
4 deletions
+95
-4
go/zodb/zodbtools/watch.go
go/zodb/zodbtools/watch.go
+2
-2
go/zodb/zodbtools/watch_test.go
go/zodb/zodbtools/watch_test.go
+93
-2
No files found.
go/zodb/zodbtools/watch.go
View file @
f8859a39
...
...
@@ -63,7 +63,7 @@ func Watch(ctx context.Context, stor zodb.IStorage, w io.Writer, verbose bool) (
defer
xerr
.
Contextf
(
&
err
,
"%s: watch"
,
stor
.
URL
())
emitf
:=
func
(
format
string
,
argv
...
interface
{})
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
format
,
argv
)
_
,
err
:=
fmt
.
Fprintf
(
w
,
format
,
argv
...
)
return
err
}
...
...
@@ -150,7 +150,7 @@ func watchMain(argv []string) {
// TODO defer stor.Close()
err
=
Watch
(
ctx
,
stor
,
os
.
Stdout
,
verbose
)
if
err
!=
nil
{
// XXX & not canceled
if
err
!=
nil
{
prog
.
Fatal
(
err
)
}
}
go/zodb/zodbtools/watch_test.go
View file @
f8859a39
...
...
@@ -20,10 +20,101 @@
package
zodbtools
import
(
"bufio"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
)
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/neo/go/internal/xtesting"
"lab.nexedi.com/kirr/neo/go/zodb"
)
func
TestWatch
(
t
*
testing
.
T
)
{
// XXX
X
:=
exc
.
Raiseif
xtesting
.
NeedPy
(
t
,
"zodbtools"
)
work
,
err
:=
ioutil
.
TempDir
(
""
,
"t-zodbwatch"
);
X
(
err
)
defer
os
.
RemoveAll
(
work
)
tfs
:=
work
+
"/t.fs"
// force tfs creation
at
:=
zodb
.
Tid
(
0
)
xcommit
:=
func
(
objv
...
xtesting
.
ZRawObject
)
{
t
.
Helper
()
var
err
error
at
,
err
=
xtesting
.
ZPyCommitRaw
(
tfs
,
at
,
objv
...
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
xcommit
(
xtesting
.
ZRawObject
{
0
,
[]
byte
(
"data0"
)})
// spawn plain and verbose watchers
ctx0
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
wg
,
ctx
:=
errgroup
.
WithContext
(
ctx0
)
// gowatch spawns Watch(verbose) and returns expect(line) func that is
// connected to Watch output.
gowatch
:=
func
(
verbose
bool
)
/*expectf*/
func
(
format
string
,
argv
...
interface
{})
{
pr
,
pw
:=
io
.
Pipe
()
wg
.
Go
(
func
()
error
{
stor
,
err
:=
zodb
.
OpenStorage
(
ctx
,
tfs
,
&
zodb
.
OpenOptions
{
ReadOnly
:
true
})
if
err
!=
nil
{
return
err
}
return
Watch
(
ctx
,
stor
,
pw
,
verbose
)
})
r
:=
bufio
.
NewReader
(
pr
)
expectf
:=
func
(
format
string
,
argv
...
interface
{})
{
t
.
Helper
()
l
,
err
:=
r
.
ReadString
(
'\n'
)
if
err
!=
nil
{
t
.
Fatalf
(
"expect: %s"
,
err
)
}
l
=
l
[
:
len
(
l
)
-
1
]
// trim trailing \n
line
:=
fmt
.
Sprintf
(
format
,
argv
...
)
if
l
!=
line
{
t
.
Fatalf
(
"expect
\n
have: %q
\n
want: %q"
,
l
,
line
)
}
}
return
expectf
}
pexpect
:=
gowatch
(
false
)
vexpect
:=
gowatch
(
true
)
pexpect
(
"# at %s"
,
at
)
vexpect
(
"# at %s"
,
at
)
xcommit
(
xtesting
.
ZRawObject
{
0
,
[]
byte
(
"data01"
)})
pexpect
(
"txn %s"
,
at
)
vexpect
(
"txn %s"
,
at
)
vexpect
(
"obj 0000000000000000"
)
vexpect
(
""
)
xcommit
(
xtesting
.
ZRawObject
{
1
,
[]
byte
(
"data1"
)},
xtesting
.
ZRawObject
{
2
,
[]
byte
(
"data2"
)})
pexpect
(
"txn %s"
,
at
)
vexpect
(
"txn %s"
,
at
)
vexpect
(
"obj 0000000000000001"
)
vexpect
(
"obj 0000000000000002"
)
vexpect
(
""
)
cancel
()
err
=
wg
.
Wait
()
ecause
:=
errors
.
Cause
(
err
)
if
ecause
!=
context
.
Canceled
{
t
.
Fatalf
(
"finished: err: expected 'canceled' cause; got %q"
,
err
)
}
}
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