Skip to content

Instantly share code, notes, and snippets.

@maplebed
Created February 1, 2019 23:58
Show Gist options
  • Save maplebed/5eed1afa434f46ca65bc841eea8fae87 to your computer and use it in GitHub Desktop.
Save maplebed/5eed1afa434f46ca65bc841eea8fae87 to your computer and use it in GitHub Desktop.
Test script to race the go beeline by sending supposedly synchronous spans asynchronously. It should work, though the resulting spans will have some marked as having been sent early by the parent. It shouldn't deadlock, which sadly does happen against the beeline at git revision 609a95f
package main
import (
"context"
"fmt"
"runtime"
"time"
beeline "github.com/honeycombio/beeline-go"
libhoney "github.com/honeycombio/libhoney-go"
)
func one(ctx context.Context) {
_, span := beeline.StartSpan(ctx, "one")
defer span.Send()
time.Sleep(10 * time.Millisecond)
}
func two(ctx context.Context) {
_, span := beeline.StartSpan(ctx, "two")
defer span.Send()
time.Sleep(12 * time.Millisecond)
}
func three(ctx context.Context) {
ctx, span := beeline.StartSpan(ctx, "three")
defer span.Send()
go one(ctx)
two(ctx)
}
func main() {
beeline.Init(beeline.Config{
APIHost: "http://localhost:8080",
WriteKey: "xxxxxxxxxx",
Dataset: "pannn",
// Output: &libhoney.WriterOutput{},
})
libhoney.AddDynamicField("global.num_goroutines",
func() interface{} { return runtime.NumGoroutine() })
done := time.Tick(75 * time.Second)
for {
fmt.Println("looping")
select {
case <-done:
fmt.Println("done")
return
default:
fmt.Println("default")
}
ctx, span := beeline.StartSpan(context.Background(), "root")
one(ctx)
two(ctx)
go three(ctx)
go one(ctx)
go two(ctx)
fmt.Println("a")
two(ctx)
fmt.Println("b")
span.Send()
fmt.Println("c")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment