github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/broker/federation/pooled_worker_test.go (about)

     1  // Copyright (c) 2017-2021, R.I. Pienaar and the Choria Project contributors
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package federation
     6  
     7  import (
     8  	"context"
     9  	"io"
    10  
    11  	. "github.com/onsi/ginkgo/v2"
    12  	. "github.com/onsi/gomega"
    13  	log "github.com/sirupsen/logrus"
    14  )
    15  
    16  var _ = Describe("Pooled Worker", func() {
    17  	var s, l, r *pooledWorker
    18  
    19  	BeforeEach(func() {
    20  		log.SetOutput(io.Discard)
    21  		logger := log.WithFields(log.Fields{"test": "true"})
    22  		broker := &FederationBroker{}
    23  
    24  		s, _ = PooledWorkerFactory("socket", 1, Unconnected, 1000, broker, logger, func(ctx context.Context, w *pooledWorker, i int, l *log.Entry) {})
    25  		l, _ = PooledWorkerFactory("left", 1, Unconnected, 1000, broker, logger, func(ctx context.Context, w *pooledWorker, i int, l *log.Entry) {})
    26  		r, _ = PooledWorkerFactory("right", 1, Unconnected, 1000, broker, logger, func(ctx context.Context, w *pooledWorker, i int, l *log.Entry) {})
    27  	})
    28  
    29  	It("Should correctly initialize", func() {
    30  		Expect(s.Name()).To(Equal("socket"))
    31  		Expect(s.mode).To(Equal(Unconnected))
    32  		Expect(s.capacity).To(Equal(1000))
    33  		Expect(s.Input()).To(HaveCap(1000))
    34  		Expect(s.Output()).To(HaveCap(1000))
    35  		Expect(s.Ready()).To(BeTrue())
    36  	})
    37  
    38  	It("Should correctly plug chainables into each other", func() {
    39  		Expect(l.Output()).ToNot(Equal(s.Input()))
    40  		err := s.From(l)
    41  		Expect(err).ToNot(HaveOccurred())
    42  		Expect(l.Output()).To(Equal(s.Input()))
    43  
    44  		Expect(r.Input()).ToNot(Equal(s.Output()))
    45  		err = s.To(r)
    46  		Expect(err).ToNot(HaveOccurred())
    47  		Expect(r.Input()).To(Equal(s.Output()))
    48  	})
    49  })