-
Notifications
You must be signed in to change notification settings - Fork 3
/
mdb_test.go
executable file
·58 lines (48 loc) · 1.05 KB
/
mdb_test.go
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
package mdb
import (
"testing"
"log"
"time"
)
func TestRefresh(t *testing.T) {
//the test is default db, you can use db.DB(dbname) to other
db, err := Dial("mongodb://127.0.0.1:27017/test")
if err != nil {
panic(err)
}
defer db.Close()
// Optional. Switch the session to a monotonic behavior.
db.SetMode(Monotonic, true)
type Person struct {
Name string
Phone string
}
c := db.C("people")
err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
&Person{"Cla", "+55 53 8402 8510"})
if err != nil {
log.Fatal(err)
}
for i := 0; i < 100; i++ {
go func() {
c := db.C("people")
for i := 0; i < 900; i++ {
err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
&Person{"Cla", "+55 53 8402 8510"})
if err != nil {
log.Println(err)
continue
}
time.Sleep(500 * time.Millisecond)
err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
&Person{"Cla", "+55 53 8402 8510"})
if err != nil {
log.Println(err)
continue
}
log.Println("insert people", i)
}
}()
}
time.Sleep(time.Hour)
}