test(inputs.opcua_listener): harden tests (#12193)

This commit is contained in:
Joshua Powers 2022-11-07 13:31:07 -07:00 committed by GitHub
parent 9d18c973cf
commit 42e2c2deff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -40,7 +40,10 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
container := testutil.Container{ container := testutil.Container{
Image: "open62541/open62541", Image: "open62541/open62541",
ExposedPorts: []string{servicePort}, ExposedPorts: []string{servicePort},
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)), WaitingFor: wait.ForAll(
wait.ForListeningPort(nat.Port(servicePort)),
wait.ForLog("TCP network layer listening on opc.tcp://"),
),
} }
err := container.Start() err := container.Start()
require.NoError(t, err, "failed to start container") require.NoError(t, err, "failed to start container")
@ -95,7 +98,6 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
err = readClient.Connect() err = readClient.Connect()
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, logger.LastError, "E! [] status not OK for node ProductName")
} }
func TestReadClientIntegration(t *testing.T) { func TestReadClientIntegration(t *testing.T) {
@ -106,7 +108,10 @@ func TestReadClientIntegration(t *testing.T) {
container := testutil.Container{ container := testutil.Container{
Image: "open62541/open62541", Image: "open62541/open62541",
ExposedPorts: []string{servicePort}, ExposedPorts: []string{servicePort},
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)), WaitingFor: wait.ForAll(
wait.ForListeningPort(nat.Port(servicePort)),
wait.ForLog("TCP network layer listening on opc.tcp://"),
),
} }
err := container.Start() err := container.Start()
require.NoError(t, err, "failed to start container") require.NoError(t, err, "failed to start container")
@ -187,7 +192,7 @@ password = ""
name="name2" name="name2"
namespace="2" namespace="2"
identifier_type="s" identifier_type="s"
identifier="two" identifier="two"
tags=[["tag0", "val0"], ["tag00", "val00"]] tags=[["tag0", "val0"], ["tag00", "val00"]]
default_tags = {tag6 = "val6"} default_tags = {tag6 = "val6"}

View File

@ -41,7 +41,10 @@ func TestSubscribeClientIntegration(t *testing.T) {
container := testutil.Container{ container := testutil.Container{
Image: "open62541/open62541", Image: "open62541/open62541",
ExposedPorts: []string{servicePort}, ExposedPorts: []string{servicePort},
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)), WaitingFor: wait.ForAll(
wait.ForListeningPort(nat.Port(servicePort)),
wait.ForLog("TCP network layer listening on opc.tcp://"),
),
} }
err := container.Start() err := container.Start()
require.NoError(t, err, "failed to start container") require.NoError(t, err, "failed to start container")
@ -87,10 +90,14 @@ func TestSubscribeClientIntegration(t *testing.T) {
o, err := subscribeConfig.CreateSubscribeClient(testutil.Logger{}) o, err := subscribeConfig.CreateSubscribeClient(testutil.Logger{})
require.NoError(t, err) require.NoError(t, err)
err = o.Init() // give init a couple extra attempts, seconds as on CircleCI this can
require.NoError(t, err, "Initialization") // be attempted to soon
require.Eventually(t, func() bool {
return o.Init() == nil
}, 5*time.Second, 10*time.Millisecond)
err = o.Connect() err = o.Connect()
require.NoError(t, err, "Connect") require.NoError(t, err, "Connection failed")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel() defer cancel()