Merge pull request #139 from unistack-org/store

store: add Timeout option
This commit is contained in:
Василий Толстов 2022-07-08 22:41:47 +03:00 committed by GitHub
commit 1c0e5e1a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 2 deletions

View File

@ -7,6 +7,55 @@ import (
"github.com/silas/dag" "github.com/silas/dag"
) )
func TestDeps(t *testing.T) {
d := &dag.AcyclicGraph{}
v0 := d.Add(&node{"v0"})
v1 := d.Add(&node{"v1"})
v2 := d.Add(&node{"v2"})
v3 := d.Add(&node{"v3"})
v4 := d.Add(&node{"v4"})
d.Connect(dag.BasicEdge(v0, v1))
d.Connect(dag.BasicEdge(v1, v2))
d.Connect(dag.BasicEdge(v2, v4))
d.Connect(dag.BasicEdge(v0, v3))
d.Connect(dag.BasicEdge(v3, v4))
if err := d.Validate(); err != nil {
t.Fatal(err)
}
d.TransitiveReduction()
var steps [][]string
fn := func(n dag.Vertex, idx int) error {
if idx == 0 {
steps = make([][]string, 1)
steps[0] = make([]string, 0, 1)
} else if idx >= len(steps) {
tsteps := make([][]string, idx+1)
copy(tsteps, steps)
steps = tsteps
steps[idx] = make([]string, 0, 1)
}
steps[idx] = append(steps[idx], fmt.Sprintf("%s", n))
return nil
}
start := &node{"v0"}
err := d.SortedDepthFirstWalk([]dag.Vertex{start}, fn)
checkErr(t, err)
for idx, steps := range steps {
fmt.Printf("level %d steps %#+v\n", idx, steps)
}
if len(steps[2]) != 1 {
t.Logf("invalid steps %#+v", steps[2])
}
}
func checkErr(t *testing.T, err error) { func checkErr(t *testing.T, err error) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -301,11 +301,11 @@ func TestWatcher(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
for { for {
ch, err := wc.Next() _, err := wc.Next()
if err != nil { if err != nil {
t.Fatal("unexpected err", err) t.Fatal("unexpected err", err)
} }
t.Logf("changes %#+v", ch.Service) // t.Logf("changes %#+v", ch.Service)
wc.Stop() wc.Stop()
wg.Done() wg.Done()
return return

View File

@ -34,6 +34,8 @@ type Options struct {
Addrs []string Addrs []string
// Wrappers store wrapper that called before actual functions // Wrappers store wrapper that called before actual functions
// Wrappers []Wrapper // Wrappers []Wrapper
// Timeout specifies timeout duration for all operations
Timeout time.Duration
} }
// NewOptions creates options struct // NewOptions creates options struct
@ -110,6 +112,13 @@ func Tracer(t tracer.Tracer) Option {
} }
} }
// Timeout sets the timeout
func Timeout(td time.Duration) Option {
return func(o *Options) {
o.Timeout = td
}
}
// Addrs contains the addresses or other connection information of the backing storage. // Addrs contains the addresses or other connection information of the backing storage.
// For example, an etcd implementation would contain the nodes of the cluster. // For example, an etcd implementation would contain the nodes of the cluster.
// A SQL implementation could contain one or more connection strings. // A SQL implementation could contain one or more connection strings.