<commit_before>package nats

import (
	"bytes"
	"errors"
	"math"
	"regexp"
	"runtime"
	"sync"
	"testing"
	"time"
)

// Dumb wait program to sync on callbacks, etc.. Will timeout after 100 milliseconds
func wait(ch chan bool) error {
	select {
	case <-ch:
		return nil
	case <-time.After(100 * time.Millisecond):
	}
	return errors.New("timeout")
}

func TestCloseLeakingGoRoutines(t *testing.T) {
	base := runtime.NumGoroutine()
	nc := newConnection(t)
	time.Sleep(10 * time.Millisecond)
	nc.Close()
	time.Sleep(10 * time.Millisecond)
	delta := (runtime.NumGoroutine() - base)
	if delta > 0 {
		t.Fatalf("%d Go routines still exists post Close()", delta)
	}
	// Make sure we can call Close() multiple times
	nc.Close()
}

func TestMultipleClose(t *testing.T) {
	nc := newConnection(t)
	var wg sync.WaitGroup
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func() {
			nc.Close()<commit_msg>Increase timeout for Travis tests<commit_after>package nats

import (
	"bytes"
	"errors"
	"math"
	"regexp"
	"runtime"
	"sync"
	"testing"
	"time"
)

// Dumb wait program to sync on callbacks, etc.. Will timeout after 200 milliseconds
func wait(ch chan bool) error {
	select {
	case <-ch:
		return nil
	case <-time.After(200 * time.Millisecond):
	}
	return errors.New("timeout")
}

func TestCloseLeakingGoRoutines(t *testing.T) {
	base := runtime.NumGoroutine()
	nc := newConnection(t)
	time.Sleep(10 * time.Millisecond)
	nc.Close()
	time.Sleep(10 * time.Millisecond)
	delta := (runtime.NumGoroutine() - base)
	if delta > 0 {
		t.Fatalf("%d Go routines still exists post Close()", delta)
	}
	// Make sure we can call Close() multiple times
	nc.Close()
}

func TestMultipleClose(t *testing.T) {
	nc := newConnection(t)
	var wg sync.WaitGroup
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func() {
			nc.Close()
{'fraction_non_alphanumeric': 0.1452513966480447, 'fraction_numerical': 0.01675977653631285, 'mean_word_length': 3.8016085790884717, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '4458394', 'n_tokens_mistral': 718, 'n_tokens_neox': 669, 'n_words': 187}