<commit_before>package s26

import (
	"net"
	"runtime"
	"testing"
)

func TestS26(t *testing.T) {

}

func TestWriteToUDP(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("skipping test on %q", runtime.GOOS)
	}

	l, err := net.ListenPacket("udp", "127.0.0.1:0")
	if err != nil {
		t.Fatalf("Listen failed: %v", err)
	}
	defer l.Close()

	testWriteToConn(t, l.LocalAddr().String())
	testWriteToPacketConn(t, l.LocalAddr().String())
}

func testWriteToConn(t *testing.T, raddr string) {
	udpAddr, err := net.ResolveUDPAddr("udp", raddr)
	if err != nil {
		t.Fatalf("Resolve failed: %v", err)
	}

	c, err := net.DialUDP("udp", nil, udpAddr)
	if err != nil {
		t.Fatalf("Dial failed: %v", err)
	}
	defer c.Close()

	_, err = c.Write([]byte("Connection-oriented mode socket"))
	if err != nil {
		t.Fatalf("Write failed: %v", err)
	}
}

func testWriteToPacketConn(t *testing.T, raddr string) {
	c, err := net.ListenPacket("udp", "127.0.0.1:0")
	if err != nil {
		t.Fatalf("ListenPacket failed: %v", err)
	}
	defer c.Close()

	ra, err := net.ResolveUDPAddr("udp", raddr)
	if err != nil {
		t.Fatalf("ResolveUDPAddr failed: %v", err)
	}

	_, err = c.(*net.UDPConn).WriteToUDP([]byte("Connection-less mode socket"), ra)
	if err != nil {
		t.Fatalf("WriteToUDP failed: %v", err)
	}

	_, err = c.WriteTo([]byte("Connection-less mode socket"), ra)
	if err != nil {
		t.Fatalf("WriteTo failed: %v", err)
	}

	_, err = c.(*net.UDPConn).Write([]byte("Connection-less mode socket"))
	if err == nil {
		t.Fatal("Write should fail")
	}
}<commit_msg>Basic udp write/read test<commit_after>package s26

import (
	"net"
	"testing"
	"time"
)

func TestS26(t *testing.T) {

}

func TestWriteToUDP(t *testing.T) {
	listenAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0")
	if err != nil {
		t.Fatalf("Resolve failed: %v", err)
	}

	l, err := net.ListenUDP("udp", listenAddr)
	if err != nil {
		t.Fatalf("Listen failed: %v", err)
	}
	defer l.Close()

	message := "UDP test message"

	done := make(chan bool, 1)
	go func() {
		var b [576]byte
		i, err := l.Read(b[:])
		if err != nil {
			t.Fatalf("Read err: %v", err)
		}
		if string(b[:i]) != message {
			t.Fatalf("Expected: %v, got: %v\n", message, string(b[:i]))
		}
		done <- true
	}()

	go func(raddr string) {
		udpAddr, err := net.ResolveUDPAddr("udp", raddr)
		if err != nil {
			t.Fatalf("Resolve failed: %v", err)
		}

		c, err := net.DialUDP("udp", nil, udpAddr)
		if err != nil {
			t.Fatalf("Dial failed: %v", err)
		}
		defer c.Close()

		_, err = c.Write([]byte(message))
		if err != nil {
			t.Fatalf("Write failed: %v", err)
		}
	}(l.LocalAddr().String())

	select {
	case <-done:
	case <-time.After(2 * time.Second):
		t.Fatal("timeout waiting for UCP read")
	}

}
{'fraction_non_alphanumeric': 0.19809244314013205, 'fraction_numerical': 0.012839325018341893, 'mean_word_length': 3.5986509274873524, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '1006659', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1139, 'n_words': 264}