<commit_before>package self_test

import (
	"context"
	"fmt"
	"io/ioutil"
	"net"
	"time"

	quic "github.com/lucas-clemente/quic-go"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Stream deadline tests", func() {
	var (
		server    quic.Listener
		serverStr quic.Stream
		clientStr quic.Stream
	)

	BeforeEach(func() {
		var err error
		server, err = quic.ListenAddr("localhost:0", getTLSConfig(), nil)
		Expect(err).ToNot(HaveOccurred())
		acceptedStream := make(chan struct{})
		go func() {
			defer GinkgoRecover()
			sess, err := server.Accept(context.Background())
			Expect(err).ToNot(HaveOccurred())
			serverStr, err = sess.AcceptStream(context.Background())
			Expect(err).ToNot(HaveOccurred())
			_, err = serverStr.Read([]byte{0})
			Expect(err).ToNot(HaveOccurred())
			close(acceptedStream)
		}()

		sess, err := quic.DialAddr(
			fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
			getTLSClientConfig(),
			nil,
		)
		Expect(err).ToNot(HaveOccurred())
		clientStr, err = sess.OpenStream()
		Expect(err).ToNot(HaveOccurred())
		_, err = clientStr.Write([]byte{0}) // need to write one byte so the server learns about the stream
		Expect(err).ToNot(HaveOccurred())
		Eventually(acceptedStream).Should(BeClosed())
	})

	AfterEach(func() {
		Expect(server.Close()).To(Succeed())
	})

	Context("read deadlines", func() {
		It("completes a transfer when the deadline is set", func() {
			const timeout = 20 * time.Millisecond
			done := make(chan struct{})
			go func() {
				defer GinkgoRecover()
				_, err := serverStr.Write(PRDataLong)
				Expect(err).ToNot(HaveOccurred())
				close(done)
			}()

			var bytesRead int
			var timeoutCounter int
			buf := make([]byte, 1<<10)
			data := make([]byte, len(PRDataLong))<commit_msg>use the standard quic.Config in the deadline tests<commit_after>package self_test

import (
	"context"
	"fmt"
	"io/ioutil"
	"net"
	"time"

	quic "github.com/lucas-clemente/quic-go"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Stream deadline tests", func() {
	var (
		server    quic.Listener
		serverStr quic.Stream
		clientStr quic.Stream
	)

	BeforeEach(func() {
		var err error
		server, err = quic.ListenAddr("localhost:0", getTLSConfig(), getQuicConfig(nil))
		Expect(err).ToNot(HaveOccurred())
		acceptedStream := make(chan struct{})
		go func() {
			defer GinkgoRecover()
			sess, err := server.Accept(context.Background())
			Expect(err).ToNot(HaveOccurred())
			serverStr, err = sess.AcceptStream(context.Background())
			Expect(err).ToNot(HaveOccurred())
			_, err = serverStr.Read([]byte{0})
			Expect(err).ToNot(HaveOccurred())
			close(acceptedStream)
		}()

		sess, err := quic.DialAddr(
			fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
			getTLSClientConfig(),
			getQuicConfig(nil),
		)
		Expect(err).ToNot(HaveOccurred())
		clientStr, err = sess.OpenStream()
		Expect(err).ToNot(HaveOccurred())
		_, err = clientStr.Write([]byte{0}) // need to write one byte so the server learns about the stream
		Expect(err).ToNot(HaveOccurred())
		Eventually(acceptedStream).Should(BeClosed())
	})

	AfterEach(func() {
		Expect(server.Close()).To(Succeed())
	})

	Context("read deadlines", func() {
		It("completes a transfer when the deadline is set", func() {
			const timeout = 20 * time.Millisecond
			done := make(chan struct{})
			go func() {
				defer GinkgoRecover()
				_, err := serverStr.Write(PRDataLong)
				Expect(err).ToNot(HaveOccurred())
				close(done)
			}()

			var bytesRead int
			var timeoutCounter int
			buf := make([]byte, 1<<10)
			data := make([]byte, len(PRDataLong))
{'fraction_non_alphanumeric': 0.15983493810178817, 'fraction_numerical': 0.004401650618982118, 'mean_word_length': 4.231654676258993, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2477561', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1260, 'n_words': 250}