<commit_before>package lightstep

import (
	"testing"

	"github.com/opentracing/basictracer-go"
)

func TestMaxBufferSize(t *testing.T) {
	recorder := NewRecorder(Options{
		AccessToken: "0987654321",
	}).(*Recorder)

	checkCapSize := func(spanLen, spanCap int) {
		recorder.lock.Lock()
		defer recorder.lock.Unlock()

		if recorder.buffer.cap() != spanCap {
			t.Error("Unexpected buffer size")
		}
		if recorder.buffer.len() != spanLen {
			t.Error("Unexpected buffer size")
		}
	}

	checkCapSize(0, defaultMaxSpans)

	spans := make([]basictracer.RawSpan, defaultMaxSpans)
	for _, span := range spans {
		recorder.RecordSpan(span)
	}

	checkCapSize(defaultMaxSpans, defaultMaxSpans)

	spans = append(spans, make([]basictracer.RawSpan, defaultMaxSpans)...)
	for _, span := range spans {
		recorder.RecordSpan(span)
	}

	checkCapSize(defaultMaxSpans, defaultMaxSpans)

	maxBuffer := 10
	recorder = NewRecorder(Options{
		AccessToken:      "0987654321",
		MaxBufferedSpans: maxBuffer,
	}).(*Recorder)

	checkCapSize(0, maxBuffer)

	spans = append(spans, make([]basictracer.RawSpan, 100*defaultMaxSpans)...)
	for _, span := range spans {
		recorder.RecordSpan(span)
	}

	checkCapSize(maxBuffer, maxBuffer)
}<commit_msg>Fix recorder_test.go by properly initializing the spans. (#23)<commit_after>package lightstep

import (
	"testing"

	"github.com/opentracing/basictracer-go"
)

func makeSpanSlice(length int) []basictracer.RawSpan {
	spans := make([]basictracer.RawSpan, length)
	for i := range spans {
		spans[i].SpanContext = &basictracer.SpanContext{}
	}
	return spans
}

func TestMaxBufferSize(t *testing.T) {
	recorder := NewRecorder(Options{
		AccessToken: "0987654321",
	}).(*Recorder)

	checkCapSize := func(spanLen, spanCap int) {
		recorder.lock.Lock()
		defer recorder.lock.Unlock()

		if recorder.buffer.cap() != spanCap {
			t.Error("Unexpected buffer size")
		}
		if recorder.buffer.len() != spanLen {
			t.Error("Unexpected buffer size")
		}
	}

	checkCapSize(0, defaultMaxSpans)

	spans := makeSpanSlice(defaultMaxSpans)
	for _, span := range spans {
		recorder.RecordSpan(span)
	}

	checkCapSize(defaultMaxSpans, defaultMaxSpans)

	spans = append(spans, makeSpanSlice(defaultMaxSpans)...)
	for _, span := range spans {
		recorder.RecordSpan(span)
	}

	checkCapSize(defaultMaxSpans, defaultMaxSpans)

	maxBuffer := 10
	recorder = NewRecorder(Options{
		AccessToken:      "0987654321",
		MaxBufferedSpans: maxBuffer,
	}).(*Recorder)

	checkCapSize(0, maxBuffer)

	spans = append(spans, makeSpanSlice(100*defaultMaxSpans)...)
	for _, span := range spans {
		recorder.RecordSpan(span)
	}

	checkCapSize(maxBuffer, maxBuffer)
}
{'fraction_non_alphanumeric': 0.1326762699014405, 'fraction_numerical': 0.02122820318423048, 'mean_word_length': 4.82560706401766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6389664', 'n_tokens_mistral': 1030, 'n_tokens_neox': 929, 'n_words': 173}