Last active
July 9, 2016 11:05
-
-
Save Komosa/0dd8fd1d837f9c39016a511c93baabad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestUpdate(t *testing.T) { | |
os.RemoveAll(TEST_DATA_DIR) | |
defer os.RemoveAll(TEST_DATA_DIR) | |
if err := os.MkdirAll(TEST_DATA_DIR, 0700); err != nil { | |
t.Fatal(err) | |
} | |
if err := ioutil.WriteFile(TEST_DATA_DIR+"/number_of_partitions", []byte("2"), 0600); err != nil { | |
t.Fatal(err) | |
} | |
db, err := OpenDB(TEST_DATA_DIR) | |
if err != nil { | |
t.Fatal(err) | |
} | |
if err = db.Create("col"); err != nil { | |
t.Fatal(err) | |
} | |
col := db.Use("col") | |
id, err := col.Insert(map[string]interface{}{"a": "x"}) | |
if err != nil { | |
t.Fatal(err) | |
} | |
const N = 100 | |
var wg sync.WaitGroup | |
wg.Add(N) | |
for i := 0; i < N; i++ { | |
go func() { | |
defer wg.Done() | |
err := col.Update(id, map[string]interface{}{"a": "x"}) | |
if err != nil { | |
t.Fatal(err) | |
} | |
}() | |
} | |
wg.Wait() | |
doc, err := col.Read(id) | |
if err != nil { | |
t.Fatal(err) | |
} | |
if doc["a"] != "x" { | |
t.Fatal("unexpected result") | |
} | |
if err = db.Close(); err != nil { | |
t.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment