Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(949)

Unified Diff: impl/memory/datastore_test.go

Issue 2601513007: Remove SetFinalizer from impl/memory. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | impl/memory/gkvlite_utils.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore_test.go
diff --git a/impl/memory/datastore_test.go b/impl/memory/datastore_test.go
index c9580f0f7f1af8cad4585884b1ab52948557a426..529494159ef574f6bb30ad672d63cc08cae1bc73 100644
--- a/impl/memory/datastore_test.go
+++ b/impl/memory/datastore_test.go
@@ -6,7 +6,9 @@ package memory
import (
"errors"
+ "flag"
"fmt"
+ "runtime"
"testing"
"time"
@@ -20,6 +22,8 @@ import (
. "github.com/smartystreets/goconvey/convey"
)
+var enableMemoryTest = flag.Bool("test.memusage", false, "Enable memory usage test.")
+
type MetaGroup struct {
_id int64 `gae:"$id,1"`
_kind string `gae:"$kind,__entity_group__"`
@@ -815,3 +819,55 @@ func TestAddIndexes(t *testing.T) {
})
})
}
+
+// TestMemoryUsage performs a series of datastore operations, profiling the
+// memory usage before and after.
+//
+// This is an expensive test, and it's not really sufficiently deterministic to
+// be enabled by default. If you want to run this, use the '-test.memusage'
+// flag.
+func TestMemoryUsage(t *testing.T) {
+ if !*enableMemoryTest {
+ return
+ }
+
+ Convey("A datastore instance does not leak memory.", t, func() {
+ const rounds, items = 10, 200
+
+ // Initial memory stats.
+ var ms runtime.MemStats
+ runtime.MemProfileRate = 1
+ runtime.GC()
+ runtime.ReadMemStats(&ms)
+ initialAlloc := ms.Alloc
+
+ // Run the memory test entirely within its own function scope. This will
+ // provide a hard boundary where all associated resources should be
+ // free-able.
+ func() {
+ c := Use(context.Background())
+ for i := 0; i < rounds; i++ {
+ toPut := make([]ds.PropertyMap, items)
+ for j := range toPut {
+ toPut[j] = ds.PropertyMap{
+ "$kind": ds.MkProperty(fmt.Sprintf("kind-%d", j)),
+ "$id": ds.MkProperty(1),
+ }
+ }
+ if err := ds.Put(c, toPut); err != nil {
+ panic(err)
+ }
+
+ runtime.GC()
+ }
+ }()
+
+ for i := 0; i < 3; i++ {
+ time.Sleep(100 * time.Millisecond)
+ runtime.GC()
+ }
+ runtime.ReadMemStats(&ms)
+
+ t.Logf("Memory alloc difference is: %d", ms.Alloc-initialAlloc)
+ })
+}
« no previous file with comments | « no previous file | impl/memory/gkvlite_utils.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698