<commit_before>package conn

import (
	"bytes"
	"context"
	"fmt"
	"runtime"
	"sync"
	"testing"
	"time"

	msgio "github.com/jbenet/go-msgio"
	iconn "github.com/libp2p/go-libp2p-interface-conn"
	travis "github.com/libp2p/go-testutil/ci/travis"
)

func msgioWrap(c iconn.Conn) msgio.ReadWriter {
	return msgio.NewReadWriter(c)
}

func testOneSendRecv(t *testing.T, c1, c2 iconn.Conn) {
	mc1 := msgioWrap(c1)
	mc2 := msgioWrap(c2)

	log.Debugf("testOneSendRecv from %s to %s", c1.LocalPeer(), c2.LocalPeer())
	m1 := []byte("hello")
	if err := mc1.WriteMsg(m1); err != nil {
		t.Fatal(err)
	}
	m2, err := mc2.ReadMsg()
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(m1, m2) {
		t.Fatal("failed to send: %s %s", m1, m2)
	}
}

func testNotOneSendRecv(t *testing.T, c1, c2 iconn.Conn) {
	mc1 := msgioWrap(c1)
	mc2 := msgioWrap(c2)

	m1 := []byte("hello")
	if err := mc1.WriteMsg(m1); err == nil {
		t.Fatal("write should have failed", err)
	}
	_, err := mc2.ReadMsg()
	if err == nil {
		t.Fatal("read should have failed", err)
	}
}

func TestClose(t *testing.T) {
	// t.Skip("Skipping in favor of another test")

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	c1, c2, _, _ := setupSingleConn(t, ctx)

	testOneSendRecv(t, c1, c2)
	testOneSendRecv(t, c2, c1)

	c1.Close()
	testNotOneSendRecv(t, c1, c2)<commit_msg>Fix formatting for go vet<commit_after>package conn

import (
	"bytes"
	"context"
	"fmt"
	"runtime"
	"sync"
	"testing"
	"time"

	msgio "github.com/jbenet/go-msgio"
	iconn "github.com/libp2p/go-libp2p-interface-conn"
	travis "github.com/libp2p/go-testutil/ci/travis"
)

func msgioWrap(c iconn.Conn) msgio.ReadWriter {
	return msgio.NewReadWriter(c)
}

func testOneSendRecv(t *testing.T, c1, c2 iconn.Conn) {
	mc1 := msgioWrap(c1)
	mc2 := msgioWrap(c2)

	log.Debugf("testOneSendRecv from %s to %s", c1.LocalPeer(), c2.LocalPeer())
	m1 := []byte("hello")
	if err := mc1.WriteMsg(m1); err != nil {
		t.Fatal(err)
	}
	m2, err := mc2.ReadMsg()
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(m1, m2) {
		t.Fatalf("failed to send: %s %s", m1, m2)
	}
}

func testNotOneSendRecv(t *testing.T, c1, c2 iconn.Conn) {
	mc1 := msgioWrap(c1)
	mc2 := msgioWrap(c2)

	m1 := []byte("hello")
	if err := mc1.WriteMsg(m1); err == nil {
		t.Fatal("write should have failed", err)
	}
	_, err := mc2.ReadMsg()
	if err == nil {
		t.Fatal("read should have failed", err)
	}
}

func TestClose(t *testing.T) {
	// t.Skip("Skipping in favor of another test")

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	c1, c2, _, _ := setupSingleConn(t, ctx)

	testOneSendRecv(t, c1, c2)
	testOneSendRecv(t, c2, c1)

	c1.Close()
	testNotOneSendRecv(t, c1, c2)
{'fraction_non_alphanumeric': 0.17579143389199256, 'fraction_numerical': 0.02905027932960894, 'mean_word_length': 4.039399624765478, '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': '47789', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1212, 'n_words': 251}