MCPcopy Create free account
hub / github.com/golang/appengine / testRunInBackground

Function testRunInBackground

v2/runtime/runtime_test.go:24–101  ·  view source on GitHub ↗
(t *testing.T, sendFirst bool)

Source from the content-addressed store, hash-verified

22func TestRunInBackgroundRecvFirst(t *testing.T) { testRunInBackground(t, false) }
23
24func testRunInBackground(t *testing.T, sendFirst bool) {
25 srv := httptest.NewServer(nil)
26 defer srv.Close()
27
28 const id = "f00bar"
29 sendWait, recvWait := make(chan bool), make(chan bool)
30 sbr := make(chan bool) // strobed when system.StartBackgroundRequest has started
31
32 calls := 0
33 c := aetesting.FakeSingleContext(t, "system", "StartBackgroundRequest", func(req *pb.StartBackgroundRequestRequest, res *pb.StartBackgroundRequestResponse) error {
34 calls++
35 if calls > 1 {
36 t.Errorf("Too many calls to system.StartBackgroundRequest")
37 }
38 sbr <- true
39 res.RequestId = proto.String(id)
40 <-sendWait
41 return nil
42 })
43
44 var c2 context.Context // a fake
45 newContext = func(*http.Request) context.Context {
46 return c2
47 }
48
49 var fRun int
50 f := func(c3 context.Context) {
51 fRun++
52 if c3 != c2 {
53 t.Errorf("f got a different context than expected")
54 }
55 }
56
57 ribErrc := make(chan error)
58 go func() {
59 ribErrc <- RunInBackground(c, f)
60 }()
61
62 brErrc := make(chan error)
63 go func() {
64 <-sbr
65 req, err := http.NewRequest("GET", srv.URL+"/_ah/background", nil)
66 if err != nil {
67 brErrc <- fmt.Errorf("http.NewRequest: %v", err)
68 return
69 }
70 req.Header.Set("X-AppEngine-BackgroundRequest", id)
71 client := &http.Client{
72 Transport: &http.Transport{
73 Proxy: http.ProxyFromEnvironment,
74 },
75 }
76
77 <-recvWait
78 _, err = client.Do(req)
79 brErrc <- err
80 }()
81

Callers 2

Calls 6

FakeSingleContextFunction · 0.92
RunInBackgroundFunction · 0.70
NewRequestMethod · 0.65
CloseMethod · 0.45
StringMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…