<commit_before>package network

import (
	"io/ioutil"
	"net/http"
	"testing"
	"time"
)

func TestHTTPProxy(t *testing.T) {
	s, err := NewServer(nil, 0)
	if err != nil {
		t.Fatal(err)
	}
	go func() {
		if err := s.Listen(); err != nil {
			t.Fatal(err)
		}
	}()
	time.Sleep(10 * time.Millisecond)

	// Test endpoint
	expectedResp := "foo"
	s.HTTPHandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(expectedResp))
	})
	baseURL := "http://" + s.LocalID()
	url := baseURL + "/test"
	resp, err := http.Get(url)
	if err != nil {
		t.Fatal(err)
	}
	body, _ := ioutil.ReadAll(resp.Body)
	if string(body) != expectedResp {
		t.Errorf("http.Get(%s) = %s; not %s", url, body, expectedResp)
	}
}<commit_msg>Added waitgroup to initialization before running webrequests<commit_after>package network

import (
	"io/ioutil"
	"net/http"
	"sync"
	"testing"
)

func TestHTTPProxy(t *testing.T) {
	s, err := NewServer(nil, 0)
	if err != nil {
		t.Fatal(err)
	}
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		go wg.Done()
		if err := s.Listen(); err != nil {
			t.Fatal(err)
		}
	}()
	wg.Wait()

	// Test endpoint
	expectedResp := "foo"
	s.HTTPHandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(expectedResp))
	})
	baseURL := "http://" + s.LocalID()
	url := baseURL + "/test"
	resp, err := http.Get(url)
	if err != nil {
		t.Fatal(err)
	}
	body, _ := ioutil.ReadAll(resp.Body)
	if string(body) != expectedResp {
		t.Errorf("http.Get(%s) = %s; not %s", url, body, expectedResp)
	}
}
{'fraction_non_alphanumeric': 0.19306282722513088, 'fraction_numerical': 0.0032722513089005235, 'mean_word_length': 3.537091988130564, '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': '2184307', 'n_tokens_mistral': 668, 'n_tokens_neox': 627, 'n_words': 137}