Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Add Cancellation sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
egonelbre committed Dec 26, 2018
1 parent 96b1cb6 commit 72648bb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion internal/suggest/suggest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package suggest_test

import (
"bytes"
"context"
"encoding/json"
"flag"
"io/ioutil"
Expand Down Expand Up @@ -112,10 +113,10 @@ func testRegress(t *testing.T, testDir string) {
Logf: func(string, ...interface{}) {},
Context: &suggest.PackedContext{},
}
cfg.Logf = func(string, ...interface{}) {}
if testing.Verbose() {
cfg.Logf = t.Logf
}

if cfgJSON, err := os.Open(filepath.Join(testDir, "config.json")); err == nil {
if err := json.NewDecoder(cfgJSON).Decode(&cfg); err != nil {
t.Errorf("Decode failed: %v", err)
Expand All @@ -136,3 +137,25 @@ func testRegress(t *testing.T, testDir string) {
}
return
}

func TestCancellation(t *testing.T) {
// sanity check for cancellation
ctx, cancel := context.WithCancel(context.Background())

cfg := suggest.Config{
RequestContext: ctx,
Logf: func(string, ...interface{}) {},
Context: &suggest.PackedContext{},
}
if testing.Verbose() {
cfg.Logf = t.Logf
}

data, err := ioutil.ReadFile("suggest_test.go")
if err != nil {
t.Fatal(err)
}

cancel()
_, _ = cfg.Suggest("suggest_test.go", data, 100)
}

0 comments on commit 72648bb

Please sign in to comment.