<commit_before>// Copyright (c) 2013, <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.

// Some inspiration for this test strategy comes from the
// src/pkg/net/conn_test.go example in the Go library.

package ratelimit

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

// The idea here is to create a connection with the given
// rate limits (rlim, wlim), send npack messages of length
// lpack from client to server, and finally have the server
// check whether it took within 20% of the expected duration.
//
// Testing against absolute times is a bad idea, especially
// if we want to test the case without rate limits as well.
// In fact I had to remove that case because it wouldn't
// run even remotely reliably. I am open to suggestions.

type testCase struct {
	net   string
	addr  string
	rlim  int
	wlim  int
	npack int
	lpack int
	total time.Duration
}

const accuracy = 0.2

var tests = []testCase{
//	{"tcp", "127.0.0.1:8080", 0, 0, 8, 1024, time.Duration(13 * time.Microsecond)},
	{"tcp", "127.0.0.1:8080", 4096, 0, 8, 1024, time.Duration(2 * time.Second)},
	{"tcp", "127.0.0.1:8080", 0, 4096, 8, 1024, time.Duration(2 * time.Second)},
	{"tcp", "127.0.0.1:8080", 2048, 4096, 8, 1024, time.Duration(4 * time.Second)},
	{"tcp", "127.0.0.1:8080", 4096, 2048, 8, 1024, time.Duration(4 * time.Second)},
}

func TestBoundaries(t *testing.T) {
	_, err := New(nil, -1, 10)
	if err == nil {
		t.Errorf("expected New to fail but it didn't")
	}
	_, err = New(nil, 10, -1)
	if err == nil {
		t.Errorf("expected New to fail but it didn't")
	}
}

func TestConnections(t *testing.T) {
	for _, info := range tests {
		testConnection(t, info)
	}
}<commit_msg>Added stress test: Write() will block.<commit_after>// Copyright (c) 2013, <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.

// Some inspiration for this test strategy comes from the
// src/pkg/net/conn_test.go example in the Go library.

package ratelimit

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

// The idea here is to create a connection with the given
// rate limits (rlim, wlim), send npack messages of length
// lpack from client to server, and finally have the server
// check whether it took within 20% of the expected duration.
//
// Testing against absolute times is a bad idea, especially
// if we want to test the case without rate limits as well.
// In fact I had to remove that case because it wouldn't
// run even remotely reliably. I am open to suggestions.

type testCase struct {
	net   string
	addr  string
	rlim  int
	wlim  int
	npack int
	lpack int
	total time.Duration
}

const accuracy = 0.2

var tests = []testCase{
//	{"tcp", "127.0.0.1:8080", 0, 0, 8, 1024, time.Duration(13 * time.Microsecond)},
	{"tcp", "127.0.0.1:8080", 4096, 0, 8, 1024, time.Duration(2 * time.Second)},
	{"tcp", "127.0.0.1:8080", 0, 4096, 8, 1024, time.Duration(2 * time.Second)},
	{"tcp", "127.0.0.1:8080", 2048, 4096, 8, 1024, time.Duration(4 * time.Second)},
	{"tcp", "127.0.0.1:8080", 4096, 2048, 8, 1024, time.Duration(4 * time.Second)},
	{"tcp", "127.0.0.1:8080", 16384, 0, 128, 16384, time.Duration(128 * time.Second)},
}

func TestBoundaries(t *testing.T) {
	_, err := New(nil, -1, 10)
	if err == nil {
		t.Errorf("expected New to fail but it didn't")
	}
	_, err = New(nil, 10, -1)
	if err == nil {
		t.Errorf("expected New to fail but it didn't")
	}
}

func TestConnections(t *testing.T) {
	for _, info := range tests {
		if testing.Short() && info.npack*info.lpack > 1024*1024 {
		        t.Skip("skipping test in short mode")
		        continue
		}
		testConnection(t, info)
	}
}
{'fraction_non_alphanumeric': 0.14304956896551724, 'fraction_numerical': 0.07570043103448276, 'mean_word_length': 3.347775175644028, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 11, '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': '5592091', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1285, 'n_words': 489}