<commit_before>// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package udplistener

import (
	"context"
	"fmt"
	"net"
	"reflect"
	"sync"
	"testing"
	"time"

	"github.com/golang/protobuf/proto"
	"github.com/google/cloudprober/logger"
	"github.com/google/cloudprober/message"
	"github.com/google/cloudprober/metrics"
	"github.com/google/cloudprober/probes/options"
	"github.com/google/cloudprober/probes/probeutils"
	"github.com/google/cloudprober/sysvars"
	"github.com/google/cloudprober/targets"
)

type serverConnStats struct {
	sync.Mutex
	msgCt map[string]int
}

// inputState contols the probes that run.
type inputState struct {
	seq           []int  // outgoing message seq# in order.
	src           string // outgoing message src.
	echoMode      bool   // controls whether server response to messages.
	statsInterval int32  // stats export interval (which resets counters).
	postTxSleep   string // duration to sleep after sending pkts.
}

const (
	localhost            = "localhost"
	interval             = time.Second
	timeout              = time.Second
	defaultServerType    = ProbeConf_DISCARD
	defaultStatsInterval = int32(3600000)
)

var (
	mZero = metrics.NewInt(0)
)

func sendPktsAndCollectReplies(ctx context.Context, t *testing.T, srvPort int, inp *inputState) []int {
	ctx, cancel := context.WithCancel(ctx)
	maxLen := 1024
	conn, err := net.ListenUDP("udp", nil)
	if err != nil {
		t.Fatalf("Starting UDP sender failed: %v", err)
	}
	t.Logf("Sender addr: %s", conn.LocalAddr().String())
	srvAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", srvPort))
	if err != nil {
		t.Fatalf("Error resolving udp addr for ':%d': %v", srvPort, err)<commit_msg>Use IPv4 address as sendto argument for Travis.<commit_after>// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package udplistener

import (
	"context"
	"fmt"
	"net"
	"os"
	"reflect"
	"sync"
	"testing"
	"time"

	"github.com/golang/protobuf/proto"
	"github.com/google/cloudprober/logger"
	"github.com/google/cloudprober/message"
	"github.com/google/cloudprober/metrics"
	"github.com/google/cloudprober/probes/options"
	"github.com/google/cloudprober/probes/probeutils"
	"github.com/google/cloudprober/sysvars"
	"github.com/google/cloudprober/targets"
)

type serverConnStats struct {
	sync.Mutex
	msgCt map[string]int
}

// inputState contols the probes that run.
type inputState struct {
	seq           []int  // outgoing message seq# in order.
	src           string // outgoing message src.
	echoMode      bool   // controls whether server response to messages.
	statsInterval int32  // stats export interval (which resets counters).
	postTxSleep   string // duration to sleep after sending pkts.
}

const (
	localhost            = "localhost"
	interval             = time.Second
	timeout              = time.Second
	defaultServerType    = ProbeConf_DISCARD
	defaultStatsInterval = int32(3600000)
)

var (
	mZero = metrics.NewInt(0)
)

func sendPktsAndCollectReplies(ctx context.Context, t *testing.T, srvPort int, inp *inputState) []int {
	ctx, cancel := context.WithCancel(ctx)
	maxLen := 1024
	conn, err := net.ListenUDP("udp", nil)
	if err != nil {
		t.Fatalf("Starting UDP sender failed: %v", err)
	}
	t.Logf("Sender addr: %s", conn.LocalAddr().String())
	var ip string
	if _, ok := os.LookupEnv("TRAVIS"); ok {
		ip = "127.0.0.1"
	} else if _, ok := os.LookupEnv("APPVEYOR"); ok {
		ip = "127.0.0.1"
	}
	srvAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", ip, srvPort))
	if err != nil {
		t.Fatalf("Error resolving udp addr for '%s:%d': %v", ip, srvPort, err)
{'fraction_non_alphanumeric': 0.11979279084826247, 'fraction_numerical': 0.013166414849989207, 'mean_word_length': 3.503401360544218, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '6256132', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1482, 'n_words': 455}