<commit_before>package gubled

import (
	"github.com/smancke/guble/client"
	"github.com/smancke/guble/protocol"
	"github.com/smancke/guble/server"

	"github.com/stretchr/testify/assert"
	"testing"

	"encoding/json"
	"time"
)

func TestSimplePingPong(t *testing.T) {
	_, client1, client2, tearDown := initServerAndClients(t)
	defer tearDown()

	client1.Subscribe("/foo")
	expectStatusMessage(t, client1, protocol.SUCCESS_SUBSCRIBED_TO, "/foo")

	client2.Send("/foo 42", "Hello", `{"key": "value"}`)
	expectStatusMessage(t, client2, protocol.SUCCESS_SEND, "42")
	// time.Sleep(time.Millisecond * 10)

	select {
	case msg := <-client1.Messages():
		assert.Equal(t, "Hello", msg.BodyAsString())
		assert.Equal(t, "user2", msg.UserID)
		assert.Equal(t, `{"key": "value"}`, msg.HeaderJSON)
		assert.Equal(t, uint64(1), msg.ID)
	case msg := <-client1.Errors():
		t.Logf("received error: %v", msg)
		t.FailNow()
	case <-time.After(time.Millisecond * 100):
		t.Log("no message received")
		t.FailNow()
	}
}

func initServerAndClients(t *testing.T) (*server.Service, client.Client, client.Client, func()) {
	service := StartupService(Args{Listen: "localhost:0", KVBackend: "memory"})

	time.Sleep(time.Millisecond * 100)
<commit_msg>Remove PingPong method<commit_after>package gubled

import (
	"github.com/smancke/guble/client"
	"github.com/smancke/guble/protocol"
	"github.com/smancke/guble/server"

	"github.com/stretchr/testify/assert"
	"testing"

	"encoding/json"
	"time"
)

// func TestSimplePingPong(t *testing.T) {
// 	_, client1, client2, tearDown := initServerAndClients(t)
// 	defer tearDown()

// 	client1.Subscribe("/foo")
// 	expectStatusMessage(t, client1, protocol.SUCCESS_SUBSCRIBED_TO, "/foo")

// 	client2.Send("/foo 42", "Hello", `{"key": "value"}`)
// 	expectStatusMessage(t, client2, protocol.SUCCESS_SEND, "42")
// 	// time.Sleep(time.Millisecond * 10)

// 	select {
// 	case msg := <-client1.Messages():
// 		assert.Equal(t, "Hello", msg.BodyAsString())
// 		assert.Equal(t, "user2", msg.UserID)
// 		assert.Equal(t, `{"key": "value"}`, msg.HeaderJSON)
// 		assert.Equal(t, uint64(1), msg.ID)
// 	case msg := <-client1.Errors():
// 		t.Logf("received error: %v", msg)
// 		t.FailNow()
// 	case <-time.After(time.Millisecond * 100):
// 		t.Log("no message received")
// 		t.FailNow()
// 	}
// }

func initServerAndClients(t *testing.T) (*server.Service, client.Client, client.Client, func()) {
	service := StartupService(Args{Listen: "localhost:0", KVBackend: "memory"})

	time.Sleep(time.Millisecond * 100)

{'fraction_non_alphanumeric': 0.192780642602142, 'fraction_numerical': 0.019833399444664817, 'mean_word_length': 4.447084233261339, 'pattern_counts': {'":': 4, '<': 9, '<?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': '4196620', 'n_tokens_mistral': 1040, 'n_tokens_neox': 970, 'n_words': 164}