Esempio n. 1
0
func startClique(cfg config.Config, args ...string) (*runner.ClqProcess, error) {
	if useIperf && !cfg.UseIperf {
		cfg.UseIperf = true
		cfg.IperfPort = testhelpers.SelectPort(GinkgoParallelNode())
	}

	configFile, err := ioutil.TempFile("", "clique-agent-config")
	if err != nil {
		return nil, err
	}
	configFilePath := configFile.Name()

	encoder := json.NewEncoder(configFile)
	if err := encoder.Encode(cfg); err != nil {
		configFile.Close()
		os.Remove(configFilePath)
		return nil, err
	}
	configFile.Close()

	finalArgs := []string{"-config", configFilePath, "-debug"}
	finalArgs = append(finalArgs, args...)
	cmd := exec.Command(cliqueAgentBin, finalArgs...)

	buffer := gbytes.NewBuffer()
	cmd.Stdout = io.MultiWriter(buffer, GinkgoWriter)
	cmd.Stderr = io.MultiWriter(buffer, GinkgoWriter)

	if err := cmd.Start(); err != nil {
		os.Remove(configFilePath)
		return nil, err
	}

	Eventually(buffer).Should(gbytes.Say("Clique Agent"))

	return &runner.ClqProcess{
		Cmd:           cmd,
		Buffer:        buffer,
		Config:        cfg,
		ConfigDirPath: configFilePath,
	}, nil
}
Esempio n. 2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("Logging", func() {
	var (
		tPortA, tPortB uint16
		procA, procB   *runner.ClqProcess
		hosts          []string
	)

	BeforeEach(func() {
		var err error

		tPortA = testhelpers.SelectPort(GinkgoParallelNode())
		tPortB = testhelpers.SelectPort(GinkgoParallelNode())
		hosts = []string{
			fmt.Sprintf("127.0.0.1:%d", tPortA),
			fmt.Sprintf("127.0.0.1:%d", tPortB),
		}

		procA, err = startClique(config.Config{
			TransferPort:     tPortA,
			RemoteHosts:      []string{hosts[1]},
			InitTransferSize: 1 * 1024 * 1024,
		}, "-debug")
		Expect(err).NotTo(HaveOccurred())

		procB, err = startClique(config.Config{
			TransferPort:     tPortB,
		srcTPort, srcAPort, destTPort uint16
		srcClique, destClique         *runner.ClqProcess
		srcClient                     *api.Client
	)

	BeforeEach(func() {
		if !useIperf {
			Skip("This test can only run with Iperf.")
		}
		if runtime.GOOS != "linux" {
			Skip("This test can only run with Linux.")
		}

		var err error

		srcTPort = testhelpers.SelectPort(GinkgoParallelNode())
		srcAPort = testhelpers.SelectPort(GinkgoParallelNode())
		srcClique, err = startClique(config.Config{
			TransferPort: srcTPort,
			APIPort:      srcAPort,
		})
		Expect(err).NotTo(HaveOccurred())

		srcClient = api.NewClient(
			"127.0.0.1", srcAPort, time.Millisecond*100,
		)

		destTPort = testhelpers.SelectPort(GinkgoParallelNode())
		destClique, err = startClique(config.Config{
			TransferPort: destTPort,
		})
Esempio n. 4
0
var _ = Describe("Roundtrip", func() {
	var (
		logger       *logrus.Logger
		receiver     *iperf.Receiver
		sender       *iperf.Sender
		senderConn   net.Conn
		receiverConn net.Conn
	)

	BeforeEach(func() {
		logger = &logrus.Logger{
			Out:       GinkgoWriter,
			Level:     logrus.DebugLevel,
			Formatter: new(logrus.TextFormatter),
		}
		iperfPort := testhelpers.SelectPort(GinkgoParallelNode())

		receiver = iperf.NewReceiver(logger, iperfPort)
		sender = iperf.NewSender(logger)

		senderConn, receiverConn = net.Pipe()
	})

	AfterEach(func() {
		Expect(senderConn.Close()).To(Succeed())
		Expect(receiverConn.Close()).To(Succeed())
	})

	Context("when the connection is closed", func() {
		var (
			senderConn   net.Conn
Esempio n. 5
0
	"github.com/ice-stuff/clique/testhelpers"
	"github.com/ice-stuff/clique/transfer"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Connector", func() {
	var (
		connector  transfer.Connector
		randomPort uint16
	)

	BeforeEach(func() {
		connector = transfer.NewConnector()
		randomPort = testhelpers.SelectPort(GinkgoParallelNode())
	})

	Context("when no server is listening", func() {
		It("should return an error when the listener is not running", func() {
			_, err := connector.Connect(net.ParseIP("127.0.0.1"), randomPort)
			Expect(err).To(MatchError(ContainSubstring("connection refused")))
		})
	})

	Context("when a server is listening", func() {
		var listener net.Listener

		BeforeEach(func() {
			var err error
			listener, err = net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", randomPort))