Skip to content

Commit

Permalink
invoke GC at random places
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbasit authored and zenhack committed Oct 12, 2015
1 parent 0f6e451 commit 282418a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
40 changes: 40 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package notmuch
import (
"path"
"reflect"
"runtime"
"testing"
"time"
)
Expand Down Expand Up @@ -73,6 +74,11 @@ func TestMessageReplies(t *testing.T) {
var count int
for replies.Next(msg) {
count++

// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}
if want, got := 2, count; want != got {
t.Errorf("msg.Replies(): want %d replies got %d", want, got)
Expand Down Expand Up @@ -133,6 +139,11 @@ func TestMessageFilenames(t *testing.T) {
fns := msg.Filenames()
for fns.Next(&fn) {
count++

// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}

if want, got := 2, count; want != got {
Expand Down Expand Up @@ -178,6 +189,9 @@ func TestMessageHeader(t *testing.T) {
if msg.ID() == "1258471718-6781-2-git-send-email-dottedmag@dottedmag.net" {
break
}

// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
for _, hn := range []string{"References", "references"} {
if want, got := "<1258471718-6781-1-git-send-email-dottedmag@dottedmag.net>", msg.Header(hn); want != got {
Expand All @@ -203,13 +217,17 @@ func TestMessageTags(t *testing.T) {
if msg.ID() == "1258471718-6781-2-git-send-email-dottedmag@dottedmag.net" {
break
}
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}

ts := msg.Tags()
tag := &Tag{}
var tags []string
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand All @@ -233,13 +251,17 @@ func TestMessageAddRemoveTagReadonlyDB(t *testing.T) {
if msg.ID() == "1258471718-6781-2-git-send-email-dottedmag@dottedmag.net" {
break
}
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}

ts := msg.Tags()
tag := &Tag{}
var tags []string
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand Down Expand Up @@ -276,13 +298,17 @@ func TestMessageAddRemoveTag(t *testing.T) {
if msg.ID() == "1258471718-6781-2-git-send-email-dottedmag@dottedmag.net" {
break
}
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}

ts := msg.Tags()
tag := &Tag{}
var tags []string
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand All @@ -296,6 +322,8 @@ func TestMessageAddRemoveTag(t *testing.T) {
tags = []string{}
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", tn, "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand All @@ -308,6 +336,8 @@ func TestMessageAddRemoveTag(t *testing.T) {
tags = []string{}
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand All @@ -320,6 +350,8 @@ func TestMessageAddRemoveTag(t *testing.T) {
tags = []string{}
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand Down Expand Up @@ -347,13 +379,17 @@ func TestMessageAtomic(t *testing.T) {
if msg.ID() == "1258471718-6781-2-git-send-email-dottedmag@dottedmag.net" {
break
}
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}

ts := msg.Tags()
tag := &Tag{}
var tags []string
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand All @@ -369,6 +405,8 @@ func TestMessageAtomic(t *testing.T) {
tags = []string{}
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", tn, "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand All @@ -383,6 +421,8 @@ func TestMessageAtomic(t *testing.T) {
tags = []string{}
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("msg.Tags(): want %v got %v", want, got)
Expand Down
13 changes: 12 additions & 1 deletion query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ package notmuch
// Licensed under the GPLv3 or later.
// See COPYING at the root of the repository for details.

import "testing"
import (
"runtime"
"testing"
)

func TestSearchThreads(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
Expand All @@ -22,6 +25,10 @@ func TestSearchThreads(t *testing.T) {
thread := &Thread{}
for threads.Next(thread) {
count++
// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}

if want, got := 24, count; want != got {
Expand All @@ -45,6 +52,10 @@ func TestGetNoResult(t *testing.T) {
thread := &Thread{}
for threads.Next(thread) {
count++
// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}

if want, got := 0, count; want != got {
Expand Down
16 changes: 16 additions & 0 deletions thread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package notmuch
import (
"errors"
"reflect"
"runtime"
"testing"
"time"
)
Expand Down Expand Up @@ -88,6 +89,10 @@ func TestTopLevelMessages(t *testing.T) {
var count int
for msgs.Next(message) {
count++
// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}
if want, got := 1, count; want != got {
t.Errorf("db.NewQuery(%q).Threads()[0].TopLevelMessages(): want %d got %d", qs, want, got)
Expand All @@ -114,6 +119,10 @@ func TestMessages(t *testing.T) {
var count int
for msgs.Next(message) {
count++
// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}
if want, got := 3, count; want != got {
t.Errorf("db.NewQuery(%q).Threads()[0].Messages(): want %d got %d", qs, want, got)
Expand Down Expand Up @@ -168,6 +177,11 @@ func TestAuthors(t *testing.T) {
if want, got := ress[i].unmatched, unmatched; !reflect.DeepEqual(want, got) {
t.Errorf("thread.Authors() unmatched: want %v got %v", want, got)
}

// invoke the GC to make sure it's running smoothly.
if i%2 == 0 {
runtime.GC()
}
}
}
}
Expand Down Expand Up @@ -223,6 +237,8 @@ func TestThreadTags(t *testing.T) {
var tags []string
for ts.Next(tag) {
tags = append(tags, tag.Value)
// invoke the GC to make sure it's running smoothly.
runtime.GC()
}
if want, got := []string{"inbox", "signed", "unread"}, tags; !reflect.DeepEqual(want, got) {
t.Errorf("thread.Tags(): want %v got %v", want, got)
Expand Down

0 comments on commit 282418a

Please sign in to comment.