|
| 1 | +/* |
| 2 | + Copyright The containerd Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package containerd |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "testing" |
| 22 | + "time" |
| 23 | + |
| 24 | + v1 "github.com/containerd/containerd/api/services/ttrpc/events/v1" |
| 25 | + "github.com/containerd/containerd/namespaces" |
| 26 | + "github.com/containerd/containerd/pkg/ttrpcutil" |
| 27 | + "github.com/containerd/ttrpc" |
| 28 | + "github.com/gogo/protobuf/types" |
| 29 | + "gotest.tools/assert" |
| 30 | +) |
| 31 | + |
| 32 | +func TestClientTTRPC_New(t *testing.T) { |
| 33 | + client, err := ttrpcutil.NewClient(address + ".ttrpc") |
| 34 | + assert.NilError(t, err) |
| 35 | + |
| 36 | + err = client.Close() |
| 37 | + assert.NilError(t, err) |
| 38 | +} |
| 39 | + |
| 40 | +func TestClientTTRPC_Reconnect(t *testing.T) { |
| 41 | + client, err := ttrpcutil.NewClient(address + ".ttrpc") |
| 42 | + assert.NilError(t, err) |
| 43 | + |
| 44 | + err = client.Reconnect() |
| 45 | + assert.NilError(t, err) |
| 46 | + |
| 47 | + // Send test request to make sure its alive after reconnect |
| 48 | + _, err = client.EventsService().Forward(context.Background(), &v1.ForwardRequest{ |
| 49 | + Envelope: &v1.Envelope{ |
| 50 | + Timestamp: time.Now(), |
| 51 | + Namespace: namespaces.Default, |
| 52 | + Topic: "/test", |
| 53 | + Event: &types.Any{}, |
| 54 | + }, |
| 55 | + }) |
| 56 | + assert.NilError(t, err) |
| 57 | + |
| 58 | + err = client.Close() |
| 59 | + assert.NilError(t, err) |
| 60 | +} |
| 61 | + |
| 62 | +func TestClientTTRPC_Close(t *testing.T) { |
| 63 | + client, err := ttrpcutil.NewClient(address + ".ttrpc") |
| 64 | + assert.NilError(t, err) |
| 65 | + |
| 66 | + err = client.Close() |
| 67 | + assert.NilError(t, err) |
| 68 | + |
| 69 | + _, err = client.EventsService().Forward(context.Background(), &v1.ForwardRequest{Envelope: &v1.Envelope{}}) |
| 70 | + assert.Equal(t, err, ttrpc.ErrClosed) |
| 71 | + |
| 72 | + err = client.Close() |
| 73 | + assert.NilError(t, err) |
| 74 | +} |
0 commit comments