Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions conn/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"os"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -62,10 +61,7 @@ func (n *Node) run(wg *sync.WaitGroup) {
}

func TestProposal(t *testing.T) {
dir, err := os.MkdirTemp("", "badger")
require.NoError(t, err)
defer os.RemoveAll(dir)

dir := t.TempDir()
store := raftwal.Init(dir)

rc := &pb.RaftContext{Id: 1}
Expand Down
6 changes: 3 additions & 3 deletions dgraph/cmd/live/load-json/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ func TestMain(m *testing.M) {
// Try to create any files in a dedicated temp directory that gets cleaned up
// instead of all over /tmp or the working directory.
tmpDir, err := os.MkdirTemp("", "test.tmp-")
x.Check(err)
x.Check(os.Chdir(tmpDir))
x.Panic(err)
x.Panic(os.Chdir(tmpDir))
defer os.RemoveAll(tmpDir)

_ = m.Run()
m.Run()
}
8 changes: 4 additions & 4 deletions dgraph/cmd/live/load-uids/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,15 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatalf("Error while getting a dgraph client: %v", err)
}
x.Check(dg.Alter(
x.Panic(dg.Alter(
context.Background(), &api.Operation{DropAll: true}))

// Try to create any files in a dedicated temp directory that gets cleaned up
// instead of all over /tmp or the working directory.
tmpDir, err := os.MkdirTemp("", "test.tmp-")
x.Check(err)
x.Check(os.Chdir(tmpDir))
x.Panic(err)
x.Panic(os.Chdir(tmpDir))
defer os.RemoveAll(tmpDir)

_ = m.Run()
m.Run()
}
9 changes: 2 additions & 7 deletions dgraph/cmd/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ import (

// Test `dgraph version` with an empty config file.
func TestDgraphVersion(t *testing.T) {
tmpPath, err := os.MkdirTemp("", "test.tmp-")
require.NoError(t, err)
defer os.RemoveAll(tmpPath)

tmpPath := t.TempDir()
configPath := filepath.Join(tmpPath, "config.yml")
configFile, err := os.Create(configPath)
require.NoError(t, err)
defer configFile.Close()

err = testutil.Exec(testutil.DgraphBinaryPath(), "version", "--config", configPath)
require.NoError(t, err)
require.NoError(t, testutil.Exec(testutil.DgraphBinaryPath(), "version", "--config", configPath))
}
2 changes: 1 addition & 1 deletion dql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,7 @@ func TestParseRegexp6(t *testing.T) {
}

func TestMain(m *testing.M) {
_ = m.Run()
m.Run()
}

func TestCountAtRoot(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions edgraph/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package edgraph

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -135,9 +134,7 @@ func TestValidateKeys(t *testing.T) {
func TestParseSchemaFromAlterOperation(t *testing.T) {
md := metadata.New(map[string]string{"namespace": "123"})
ctx := metadata.NewIncomingContext(context.Background(), md)
dir, err := os.MkdirTemp("", "storetest_")
defer os.RemoveAll(dir)
x.Check(err)
dir := t.TempDir()
ps, err := badger.OpenManaged(badger.DefaultOptions(dir))
x.Check(err)
defer ps.Close()
Expand Down
2 changes: 1 addition & 1 deletion ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3623,5 +3623,5 @@ func TestDropAllShouldResetGuardiansAndGroot(t *testing.T) {
func TestMain(m *testing.M) {
adminEndpoint = "http://" + testutil.SockAddrHttp + "/admin"
fmt.Printf("Using adminEndpoint for acl package: %s\n", adminEndpoint)
_ = m.Run()
m.Run()
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,5 @@ func TestMain(m *testing.M) {
authSchema, err := testutil.AppendAuthInfo(schema, algo, "../auth/sample_public_key.pem", true)
x.Panic(err)
common.BootstrapServer(authSchema, data)
_ = m.Run()
m.Run()
}
2 changes: 1 addition & 1 deletion graphql/e2e/custom_logic/custom_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3264,5 +3264,5 @@ func TestMain(m *testing.M) {
x.Log(err, "Waited for GraphQL test server to become available, but it never did.")
os.Exit(1)
}
_ = m.Run()
m.Run()
}
2 changes: 1 addition & 1 deletion graphql/e2e/directives/dgraph_directives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ func TestMain(m *testing.M) {

common.BootstrapServer(schema, data)

_ = m.Run()
m.Run()
}
2 changes: 1 addition & 1 deletion graphql/e2e/normal/normal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ func TestMain(m *testing.M) {

common.BootstrapServer(schema, data)

_ = m.Run()
m.Run()
}
2 changes: 1 addition & 1 deletion graphql/e2e/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,5 +712,5 @@ func updateGQLSchemaConcurrent(t *testing.T, schema, authority string) bool {

func TestMain(m *testing.M) {
x.Panic(common.CheckGraphQLStarted(common.GraphqlAdminURL))
_ = m.Run()
m.Run()
}
2 changes: 1 addition & 1 deletion graphql/e2e/subscription/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,5 +1061,5 @@ func TestSubscriptionWithCustomDQL(t *testing.T) {

func TestMain(m *testing.M) {
x.Panic(common.CheckGraphQLStarted(common.GraphqlAdminURL))
_ = m.Run()
m.Run()
}
2 changes: 1 addition & 1 deletion graphql/schema/schemagen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,5 @@ func TestMain(m *testing.M) {
x.Config.GraphQL = z.NewSuperFlag("lambda-url=http://localhost:8086/graphql-worker;").
MergeAndCheckDefault("lambda-url=;")
// now run the tests
_ = m.Run()
m.Run()
}
10 changes: 4 additions & 6 deletions posting/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1457,18 +1457,16 @@ func TestMain(m *testing.M) {
Config.CommitFraction = 0.10

dir, err := os.MkdirTemp("", "storetest_")
x.Check(err)
x.Panic(err)
defer os.RemoveAll(dir)

ps, err = badger.OpenManaged(badger.DefaultOptions(dir))
x.Check(err)
x.Panic(err)
// Not using posting list cache
Init(ps, 0)
schema.Init(ps)

r := m.Run()

os.RemoveAll(dir)
os.Exit(r)
m.Run()
}

func BenchmarkAddMutations(b *testing.B) {
Expand Down
25 changes: 6 additions & 19 deletions posting/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package posting
import (
"fmt"
"math"
"os"
"sync"
"testing"

Expand Down Expand Up @@ -89,9 +88,7 @@ func BenchmarkWriter(b *testing.B) {

// Vanilla TxnWriter
b.Run("TxnWriter", func(b *testing.B) {
tmpIndexDir, err := os.MkdirTemp("", "dgraph")
require.NoError(b, err)
defer os.RemoveAll(tmpIndexDir)
tmpIndexDir := b.TempDir()

dbOpts.Dir = tmpIndexDir
dbOpts.ValueDir = tmpIndexDir
Expand All @@ -114,9 +111,7 @@ func BenchmarkWriter(b *testing.B) {
})
// Single threaded BatchWriter
b.Run("WriteBatch1", func(b *testing.B) {
tmpIndexDir, err := os.MkdirTemp("", "dgraph")
require.NoError(b, err)
defer os.RemoveAll(tmpIndexDir)
tmpIndexDir := b.TempDir()

dbOpts.Dir = tmpIndexDir
dbOpts.ValueDir = tmpIndexDir
Expand All @@ -137,9 +132,7 @@ func BenchmarkWriter(b *testing.B) {
})
// Multi threaded Batchwriter with thread contention in WriteBatch
b.Run("WriteBatchMultThreadDiffWB", func(b *testing.B) {
tmpIndexDir, err := os.MkdirTemp("", "dgraph")
require.NoError(b, err)
defer os.RemoveAll(tmpIndexDir)
tmpIndexDir := b.TempDir()

dbOpts.Dir = tmpIndexDir
dbOpts.ValueDir = tmpIndexDir
Expand All @@ -165,9 +158,7 @@ func BenchmarkWriter(b *testing.B) {
})
// Multi threaded Batchwriter with thread contention in SetEntry
b.Run("WriteBatchMultThreadSameWB", func(b *testing.B) {
tmpIndexDir, err := os.MkdirTemp("", "dgraph")
require.NoError(b, err)
defer os.RemoveAll(tmpIndexDir)
tmpIndexDir := b.TempDir()

dbOpts.Dir = tmpIndexDir
dbOpts.ValueDir = tmpIndexDir
Expand All @@ -193,9 +184,7 @@ func BenchmarkWriter(b *testing.B) {
}
})
b.Run("WriteBatchSingleThreadDiffWB", func(b *testing.B) {
tmpIndexDir, err := os.MkdirTemp("", "dgraph")
require.NoError(b, err)
defer os.RemoveAll(tmpIndexDir)
tmpIndexDir := b.TempDir()

dbOpts.Dir = tmpIndexDir
dbOpts.ValueDir = tmpIndexDir
Expand All @@ -215,9 +204,7 @@ func BenchmarkWriter(b *testing.B) {
}
})
b.Run("WriteBatchSingleThreadSameWB", func(b *testing.B) {
tmpIndexDir, err := os.MkdirTemp("", "dgraph")
require.NoError(b, err)
defer os.RemoveAll(tmpIndexDir)
tmpIndexDir := b.TempDir()

dbOpts.Dir = tmpIndexDir
dbOpts.ValueDir = tmpIndexDir
Expand Down
6 changes: 2 additions & 4 deletions query/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ import (

func TestMain(m *testing.M) {
c, err := dgraphtest.NewDCloudCluster()
if err != nil {
panic(err)
}
x.Panic(err)
defer c.Cleanup()

client = c.Client()
dc = c
populateCluster()
os.Exit(m.Run())
m.Run()
}
5 changes: 2 additions & 3 deletions query/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package query

import (
"os"
"testing"

"github.com/dgraph-io/dgraph/dgraphtest"
Expand All @@ -32,8 +31,8 @@ func TestMain(m *testing.M) {

var err error
client, err = testutil.DgraphClientWithGroot(testutil.SockAddr)
x.CheckfNoTrace(err)
x.Panic(err)

populateCluster()
os.Exit(m.Run())
m.Run()
}
16 changes: 4 additions & 12 deletions raftwal/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"log"
"math"
"math/rand"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -29,9 +28,7 @@ import (

func TestEntryReadWrite(t *testing.T) {
key := []byte("badger16byteskey")
dir, err := os.MkdirTemp("", "raftwal")
require.NoError(t, err)
defer os.RemoveAll(dir)
dir := t.TempDir()
ds, err := InitEncrypted(dir, key)
require.NoError(t, err)

Expand Down Expand Up @@ -67,11 +64,9 @@ func TestEntryReadWrite(t *testing.T) {

// TestLogRotate writes enough log file entries to cause 1 file rotation.
func TestLogRotate(t *testing.T) {
dir, err := os.MkdirTemp("", "raftwal")
require.NoError(t, err)
dir := t.TempDir()
el, err := openWal(dir)
require.NoError(t, err)
defer os.RemoveAll(dir)

// Generate deterministic entries using a seed.
const SEED = 1
Expand Down Expand Up @@ -123,17 +118,14 @@ func TestLogRotate(t *testing.T) {
// TestLogGrow writes data of sufficient size to grow the log file.
func TestLogGrow(t *testing.T) {
test := func(t *testing.T, key []byte) {
dir, err := os.MkdirTemp("", "raftwal")
require.NoError(t, err)
dir := t.TempDir()
ds, err := InitEncrypted(dir, key)
require.NoError(t, err)
defer os.RemoveAll(dir)

var entries []raftpb.Entry

const numEntries = (maxNumEntries * 3) / 2

// 5KB * 30000 is ~ 150MB, this will cause the log file to grow.
var entries []raftpb.Entry
for i := 0; i < numEntries; i++ {
data := make([]byte, 5<<10)
rand.Read(data)
Expand Down
Loading