This repository was archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbt_fail.go
More file actions
93 lines (77 loc) · 1.73 KB
/
bt_fail.go
File metadata and controls
93 lines (77 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"flag"
"log"
"net/http"
_ "net/http/pprof"
"sync"
"time"
"golang.org/x/net/context"
"google.golang.org/cloud/bigtable"
)
var para = flag.Int("para", 100, "spawn para routine")
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
start := time.Now()
defer func() {
if time.Since(start) > 2*time.Minute {
log.Println("**************************************************")
log.Printf("%s elapsed! looks like a failure!", time.Since(start))
log.Println("**************************************************")
}
}()
flag.Parse()
ctx := context.Background()
client, err := bigtable.NewClient(ctx, Project, Instance)
if err != nil {
log.Fatalf("Failed to create bigtable client: %v", err)
}
tbl := client.Open(Table)
m := bigtable.NewMutation()
m.Set(Family, Column, bigtable.Now(), []byte("foobar"))
if err := tbl.Apply(ctx, Row, m); err != nil {
log.Fatalf("failed to Set: %s", err)
}
var wg sync.WaitGroup
ctx2, cancel := context.WithTimeout(ctx, 800*time.Millisecond)
go func() {
time.Sleep(600 * time.Millisecond)
cancel()
}()
for i := 0; i < *para; i++ {
wg.Add(1)
go func() {
_, err = tbl.ReadRow(ctx2, Row)
if err != nil {
log.Println(err)
}
wg.Done()
}()
}
wg.Wait()
log.Println("1st pass ok waiting 5s")
time.Sleep(5 * time.Second)
log.Println("2nd pass")
for i := 0; i < *para; i++ {
wg.Add(1)
go func() {
_, err = tbl.ReadRow(ctx2, Column)
if err != nil {
log.Println(err)
} else {
log.Println("ok")
}
wg.Done()
}()
}
wg.Wait()
log.Println("starting last call on ctx")
_, err = tbl.ReadRow(ctx, Row)
if err != nil {
log.Println("last", err)
} else {
log.Println("last ok")
}
}