-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathoutputnode_test.go
61 lines (53 loc) · 1.56 KB
/
outputnode_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
58
59
60
61
/*
* Copyright (C) 2017 Dgraph Labs, Inc. and Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package query
import (
"bufio"
"fmt"
"io/ioutil"
"runtime"
"sync"
"testing"
"github.com/stretchr/testify/require"
"github.com/dgraph-io/dgraph/types"
)
func makeFastJsonNode() *fastJsonNode {
return &fastJsonNode{
// uncoment for master branch
// attrs: map[string]*fastJsonAttr{},
//children: map[string][]*fastJsonNode{},
}
}
func TestEncodeMemory(t *testing.T) {
var wg sync.WaitGroup
for x := 0; x < runtime.NumCPU(); x++ {
n := makeFastJsonNode()
require.NotNil(t, n)
for i := 0; i < 30000; i++ {
n.AddValue(fmt.Sprintf("very long attr name %06d", i), types.ValueForType(types.StringID))
n.AddListChild(fmt.Sprintf("another long child %06d", i), &fastJsonNode{})
}
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 1000; i++ {
n.encode(bufio.NewWriter(ioutil.Discard))
}
}()
}
wg.Wait()
}