<commit_before>package RuntimeTest

import (
	"fmt"
	"os"
	"path/filepath"
	"time"

	. "github.com/cilium/cilium/test/ginkgo-ext"
	"github.com/cilium/cilium/test/helpers"
	"github.com/cilium/cilium/test/helpers/constants"

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

func runOnNetNextOnly(f func()) func() {
	if helpers.RunsOnNetNext() {
		return f
	}
	return func() {}
}

var _ = Describe("RuntimeConnectivityInVethModeTest", runtimeConnectivityTest("veth"))
var _ = Describe("RuntimeConnectivityInIpvlanModeTest", runOnNetNextOnly(runtimeConnectivityTest("ipvlan")))

// TODO(brb) Either create a dummy netdev or determine the master device at runtime
const ipvlanMasterDevice = "enp0s8"

var runtimeConnectivityTest = func(datapathMode string) func() {
	return func() {
		var (
			vm          *helpers.SSHMeta
			monitorStop = func() error { return nil }
		)

		BeforeAll(func() {
			vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)

			if datapathMode == "ipvlan" {
				vm.SetUpCiliumInIpvlanMode(ipvlanMasterDevice)
				// cilium-docker has to be restarted because the datapath mode
				// has changed
				vm.Exec("sudo systemctl restart cilium-docker")
			}

			ExpectCiliumReady(vm)
		})

		JustBeforeEach(func() {
			monitorStop = vm.MonitorStart()
		})

		AfterAll(func() {
			// Restore the datapath mode and cilium-docker
			if datapathMode == "ipvlan" {
				vm.SetUpCilium()
				vm.Exec("sudo systemctl restart cilium-docker")
			}
		})

		removeContainer := func(containerName string) {
			By("removing container %s", containerName)
			res := vm.ContainerRm(containerName)
			ExpectWithOffset(1, res).To(helpers.CMDSuccess(), "cannot delete container")
		}

		AfterEach(func() {
			vm.PolicyDelAll().ExpectSuccess("Policies cannot be deleted")
		})

		JustAfterEach(func() {
			vm.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration)
			Expect(monitorStop()).To(BeNil(), "cannot stop monitor command")
		})

		AfterFailed(func() {
			vm.ReportFailed()
		})

		Context("Basic Connectivity test", func() {

			BeforeEach(func() {
				vm.ContainerCreate(helpers.Client, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.client")
				vm.ContainerCreate(helpers.Server, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.server")
				vm.PolicyDelAll()
				vm.WaitEndpointsReady()
				err := helpers.WithTimeout(func() bool {
					if data, _ := vm.GetEndpointsNames(); len(data) < 2 {
						logger.Info("Waiting for endpoints to be ready")
						return false
					}
					return true
				}, "Endpoints are not ready", &helpers.TimeoutConfig{Timeout: 150 * time.Second})
				Expect(err).Should(BeNil())
			}, 150)

			AfterEach(func() {
				removeContainer(helpers.Client)
				removeContainer(helpers.Server)
				return<commit_msg>test: Wait for netperf server to be up before connecting to it<commit_after>package RuntimeTest

import (
	"fmt"
	"os"
	"path/filepath"
	"time"

	. "github.com/cilium/cilium/test/ginkgo-ext"
	"github.com/cilium/cilium/test/helpers"
	"github.com/cilium/cilium/test/helpers/constants"

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

func runOnNetNextOnly(f func()) func() {
	if helpers.RunsOnNetNext() {
		return f
	}
	return func() {}
}

var _ = Describe("RuntimeConnectivityInVethModeTest", runtimeConnectivityTest("veth"))
var _ = Describe("RuntimeConnectivityInIpvlanModeTest", runOnNetNextOnly(runtimeConnectivityTest("ipvlan")))

// TODO(brb) Either create a dummy netdev or determine the master device at runtime
const ipvlanMasterDevice = "enp0s8"

var runtimeConnectivityTest = func(datapathMode string) func() {
	return func() {
		var (
			vm          *helpers.SSHMeta
			monitorStop = func() error { return nil }
		)

		BeforeAll(func() {
			vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)

			if datapathMode == "ipvlan" {
				vm.SetUpCiliumInIpvlanMode(ipvlanMasterDevice)
				// cilium-docker has to be restarted because the datapath mode
				// has changed
				vm.Exec("sudo systemctl restart cilium-docker")
			}

			ExpectCiliumReady(vm)
		})

		JustBeforeEach(func() {
			monitorStop = vm.MonitorStart()
		})

		AfterAll(func() {
			// Restore the datapath mode and cilium-docker
			if datapathMode == "ipvlan" {
				vm.SetUpCilium()
				vm.Exec("sudo systemctl restart cilium-docker")
			}
		})

		removeContainer := func(containerName string) {
			By("removing container %s", containerName)
			res := vm.ContainerRm(containerName)
			ExpectWithOffset(1, res).To(helpers.CMDSuccess(), "cannot delete container")
		}

		AfterEach(func() {
			vm.PolicyDelAll().ExpectSuccess("Policies cannot be deleted")
		})

		JustAfterEach(func() {
			vm.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration)
			Expect(monitorStop()).To(BeNil(), "cannot stop monitor command")
		})

		AfterFailed(func() {
			vm.ReportFailed()
		})

		Context("Basic Connectivity test", func() {

			BeforeEach(func() {
				vm.ContainerCreate(helpers.Client, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.client")
				vm.ContainerCreate(helpers.Server, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.server")
				vm.PolicyDelAll()
				vm.WaitEndpointsReady()
				err := helpers.WithTimeout(func() bool {
					if data, _ := vm.GetEndpointsNames(); len(data) < 2 {
						logger.Info("Waiting for endpoints to be ready")
						return false
					}
					return true
				}, "Endpoints are not ready", &helpers.TimeoutConfig{Timeout: 150 * time.Second})
				Expect(err).Should(BeNil())

				err = helpers.WithTimeout(func() bool {
					res := vm.ContainerExec(helpers.Server, "netperf -H 127.0.0.1 -l 1")
					if !res.WasSuccessful() {
						logger.Info("Waiting for netserver to come up")
					}
					return res.WasSuccessful()
				}, "netserver did not come up in time", &helpers.TimeoutConfig{Timeout: 20 * time.Second})
				Expect(err).Should(BeNil(), "timeout while waiting for netserver to start inside netperf container")
			}, 150)

			AfterEach(func() {
				removeContainer(helpers.Client)
				removeContainer(helpers.Server)
				return
{'fraction_non_alphanumeric': 0.12738643844634628, 'fraction_numerical': 0.004772876892692561, 'mean_word_length': 4.043153526970954, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '5498280', 'n_tokens_mistral': 2322, 'n_tokens_neox': 2012, 'n_words': 411}