Skip to content

Commit b768dc8

Browse files
author
Ibrahim Jarif
committed
Remove ExampleDB_Subscribe Test (#1214)
The test ExampleDB_Subscribe doesn't run reliably on appveyor. This commit removes it. (cherry picked from commit e029e93)
1 parent 18a2df1 commit b768dc8

File tree

1 file changed

+0
-65
lines changed

1 file changed

+0
-65
lines changed

db_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"flag"
2424
"fmt"
2525
"io/ioutil"
26-
"log"
2726
"math"
2827
"math/rand"
2928
"os"
@@ -1796,70 +1795,6 @@ func TestMain(m *testing.M) {
17961795
os.Exit(m.Run())
17971796
}
17981797

1799-
func ExampleDB_Subscribe() {
1800-
prefix := []byte{'a'}
1801-
1802-
// This key should be printed, since it matches the prefix.
1803-
aKey := []byte("a-key")
1804-
aValue := []byte("a-value")
1805-
1806-
// This key should not be printed.
1807-
bKey := []byte("b-key")
1808-
bValue := []byte("b-value")
1809-
1810-
// Open the DB.
1811-
dir, err := ioutil.TempDir("", "badger-test")
1812-
if err != nil {
1813-
panic(err)
1814-
}
1815-
defer removeDir(dir)
1816-
db, err := Open(DefaultOptions(dir))
1817-
if err != nil {
1818-
panic(err)
1819-
}
1820-
defer db.Close()
1821-
1822-
// Create the context here so we can cancel it after sending the writes.
1823-
ctx, cancel := context.WithCancel(context.Background())
1824-
defer cancel()
1825-
1826-
// Use the WaitGroup to make sure we wait for the subscription to stop before continuing.
1827-
var wg sync.WaitGroup
1828-
wg.Add(1)
1829-
go func() {
1830-
defer wg.Done()
1831-
cb := func(kvs *KVList) error {
1832-
for _, kv := range kvs.Kv {
1833-
fmt.Printf("%s is now set to %s\n", kv.Key, kv.Value)
1834-
}
1835-
return nil
1836-
}
1837-
if err := db.Subscribe(ctx, cb, prefix); err != nil && err != context.Canceled {
1838-
panic(err)
1839-
}
1840-
log.Printf("subscription closed")
1841-
}()
1842-
1843-
// Wait for the above go routine to be scheduled.
1844-
time.Sleep(time.Second)
1845-
// Write both keys, but only one should be printed in the Output.
1846-
err = db.Update(func(txn *Txn) error { return txn.Set(aKey, aValue) })
1847-
if err != nil {
1848-
panic(err)
1849-
}
1850-
err = db.Update(func(txn *Txn) error { return txn.Set(bKey, bValue) })
1851-
if err != nil {
1852-
panic(err)
1853-
}
1854-
1855-
log.Printf("stopping subscription")
1856-
cancel()
1857-
log.Printf("waiting for subscription to close")
1858-
wg.Wait()
1859-
// Output:
1860-
// a-key is now set to a-value
1861-
}
1862-
18631798
func removeDir(dir string) {
18641799
if err := os.RemoveAll(dir); err != nil {
18651800
panic(err)

0 commit comments

Comments
 (0)