Files
bffd92622a Bump upstream collector version (#617)
- add metadata.yaml for all relevant components and use metadata
- fix the go routine leaks in component code and tests
- add TODO for handling errors wherever they are unchecked or not
handled so the behaviour doesn't change
- address lint for the most part (so we can enable it soon) except the
metricexporter that is due to be deleted and semconv which I don't want
to touch right now
- other changes required for bump


breaking changes to pay attention to

- telemetry config, address and level removed and readers should be used
- change in attributes for telemetry
- metrics at detailed level
- failures in embedded config (addressed)

---------

Co-authored-by: Nityananda Gohain <[email protected]>
2025-06-26 14:49:43 +05:30

69 lines
2.6 KiB
Go

package inmemoryreceiver
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receivertest"
)
func TestReceiverLifecycle(t *testing.T) {
require := require.New(t)
testReceiverId := uuid.NewString()
// Should be able to get a hold of the receiver after starting it.
require.Nil(GetReceiverInstance(testReceiverId), "receiver instance should not exist before Start()")
constructed, err := makeTestLogReceiver(testReceiverId)
require.Nil(err, "could not make test receiver")
err = constructed.Start(context.Background(), componenttest.NewNopHost())
require.Nil(err, "could not start test receiver")
testReceiver := GetReceiverInstance(testReceiverId)
require.NotNil(testReceiver, "could not get receiver instance by Id")
// Should not be able to start 2 receivers with the same id
constructed2, err := makeTestLogReceiver(testReceiverId)
require.Nil(err, "could not create second receiver with same id")
err = constructed2.Start(context.Background(), componenttest.NewNopHost())
require.NotNil(err, "should not be able to start another receiver with same id before shutting down the previous one")
// Should not be able to get a hold of an receiver after shutdown
_ = testReceiver.Shutdown(context.Background())
require.Nil(GetReceiverInstance(testReceiverId), "should not be able to find inmemory receiver after shutdown")
// Should be able to start a new receiver with same id after shutting down
constructed3, err := makeTestLogReceiver(testReceiverId)
require.Nil(err, "could not make receiver with same Id after shutting down old one")
err = constructed3.Start(context.Background(), componenttest.NewNopHost())
require.Nil(err, "should be able to start another receiver with same id after shutting down the previous one")
testReceiver3 := GetReceiverInstance(testReceiverId)
require.NotNil(testReceiver3, "could not get receiver instance by Id")
_ = testReceiver3.Shutdown(context.Background())
require.Nil(GetReceiverInstance(testReceiverId))
}
func makeTestLogReceiver(receiverId string) (receiver.Logs, error) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
_ = confmap.NewFromStringMap(map[string]any{"id": receiverId}).Unmarshal(&cfg)
return factory.CreateLogs(
context.Background(), receivertest.NewNopSettings(component.MustNewType("memory")), cfg, consumertest.NewNop(),
)
}