Skip to content

Commit 559fe28

Browse files
committed
add tests
1 parent a2f778a commit 559fe28

File tree

3 files changed

+511
-112
lines changed

3 files changed

+511
-112
lines changed

.github/workflows/ci.yml

Lines changed: 92 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -113,97 +113,97 @@ jobs:
113113
OS_RELEASE="${{ matrix.container.image }}" OS_VERSION="${{ matrix.container.version }}" \
114114
make integration-test
115115
116-
# official-oss-image-integration-tests:
117-
# name: Integration Tests - Official OSS Images
118-
# needs: build-unsigned-snapshot
119-
# if: ${{ !github.event.pull_request.head.repo.fork && !startsWith(github.ref_name, 'dependabot/') }}
120-
# runs-on: ubuntu-22.04
121-
# strategy:
122-
# matrix:
123-
# container:
124-
# - image: "bookworm"
125-
# version: "stable"
126-
# release: "debian"
127-
# - image: "bookworm"
128-
# version: "mainline"
129-
# release: "debian"
130-
# - image: "alpine"
131-
# version: "stable"
132-
# release: "alpine"
133-
# - image: "alpine"
134-
# version: "mainline"
135-
# release: "alpine"
136-
# steps:
137-
# - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
138-
# - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
139-
# with:
140-
# go-version-file: 'go.mod'
141-
# cache: false
142-
# - name: Download Packages
143-
# uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
144-
# with:
145-
# name: nginx-agent-unsigned-snapshots
146-
# path: build
147-
# - name: Run Integration Tests
148-
# run: |
149-
# go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
150-
# CONTAINER_NGINX_IMAGE_REGISTRY="docker-registry.nginx.com" \
151-
# TAG="${{ matrix.container.version }}-${{ matrix.container.image }}" \
152-
# OS_RELEASE="${{ matrix.container.release }}" OS_VERSION="${{ matrix.container.version }}" \
153-
# make official-image-integration-test
116+
official-oss-image-integration-tests:
117+
name: Integration Tests - Official OSS Images
118+
needs: build-unsigned-snapshot
119+
if: ${{ !github.event.pull_request.head.repo.fork && !startsWith(github.ref_name, 'dependabot/') }}
120+
runs-on: ubuntu-22.04
121+
strategy:
122+
matrix:
123+
container:
124+
- image: "bookworm"
125+
version: "stable"
126+
release: "debian"
127+
- image: "bookworm"
128+
version: "mainline"
129+
release: "debian"
130+
- image: "alpine"
131+
version: "stable"
132+
release: "alpine"
133+
- image: "alpine"
134+
version: "mainline"
135+
release: "alpine"
136+
steps:
137+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
138+
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
139+
with:
140+
go-version-file: 'go.mod'
141+
cache: false
142+
- name: Download Packages
143+
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
144+
with:
145+
name: nginx-agent-unsigned-snapshots
146+
path: build
147+
- name: Run Integration Tests
148+
run: |
149+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
150+
CONTAINER_NGINX_IMAGE_REGISTRY="docker-registry.nginx.com" \
151+
TAG="${{ matrix.container.version }}-${{ matrix.container.image }}" \
152+
OS_RELEASE="${{ matrix.container.release }}" OS_VERSION="${{ matrix.container.version }}" \
153+
make official-image-integration-test
154154
155-
# official-plus-image-integration-tests:
156-
# name: Integration Tests - Official Plus Images
157-
# needs: build-unsigned-snapshot
158-
# if: ${{ !github.event.pull_request.head.repo.fork && !startsWith(github.ref_name, 'dependabot/') }}
159-
# runs-on: ubuntu-22.04
160-
# strategy:
161-
# matrix:
162-
# container:
163-
# - image: "alpine"
164-
# version: "3.20"
165-
# plus: "r32"
166-
# release: "alpine"
167-
# path: "/nginx-plus/agent"
168-
# - image: "alpine"
169-
# version: "3.19"
170-
# plus: "r31"
171-
# release: "alpine"
172-
# path: "/nginx-plus/agent"
173-
# - image: "debian"
174-
# version: "bookworm"
175-
# plus: "r32"
176-
# release: "debian"
177-
# path: "/nginx-plus/agent"
178-
# - image: "debian"
179-
# version: "bookworm"
180-
# plus: "r31"
181-
# release: "debian"
182-
# path: "/nginx-plus/agent"
183-
# steps:
184-
# - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
185-
# - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
186-
# with:
187-
# go-version-file: 'go.mod'
188-
# cache: false
189-
# - name: Download Packages
190-
# uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
191-
# with:
192-
# name: nginx-agent-unsigned-snapshots
193-
# path: build
194-
# - name: Login to Docker Registry
195-
# uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
196-
# with:
197-
# registry: ${{ secrets.REGISTRY_URL }}
198-
# username: ${{ secrets.REGISTRY_USERNAME }}
199-
# password: ${{ secrets.REGISTRY_PASSWORD }}
200-
# - name: Run Integration Tests
201-
# run: |
202-
# go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
203-
# CONTAINER_NGINX_IMAGE_REGISTRY="${{ secrets.REGISTRY_URL }}" \
204-
# TAG="${{ matrix.container.plus }}-${{ matrix.container.image }}-${{ matrix.container.version }}" \
205-
# OS_RELEASE="${{ matrix.container.release }}" OS_VERSION="${{ matrix.container.version }}" IMAGE_PATH="${{ matrix.container.path }}" \
206-
# make official-image-integration-test
155+
official-plus-image-integration-tests:
156+
name: Integration Tests - Official Plus Images
157+
needs: build-unsigned-snapshot
158+
if: ${{ !github.event.pull_request.head.repo.fork && !startsWith(github.ref_name, 'dependabot/') }}
159+
runs-on: ubuntu-22.04
160+
strategy:
161+
matrix:
162+
container:
163+
- image: "alpine"
164+
version: "3.20"
165+
plus: "r32"
166+
release: "alpine"
167+
path: "/nginx-plus/agent"
168+
- image: "alpine"
169+
version: "3.19"
170+
plus: "r31"
171+
release: "alpine"
172+
path: "/nginx-plus/agent"
173+
- image: "debian"
174+
version: "bookworm"
175+
plus: "r32"
176+
release: "debian"
177+
path: "/nginx-plus/agent"
178+
- image: "debian"
179+
version: "bookworm"
180+
plus: "r31"
181+
release: "debian"
182+
path: "/nginx-plus/agent"
183+
steps:
184+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
185+
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
186+
with:
187+
go-version-file: 'go.mod'
188+
cache: false
189+
- name: Download Packages
190+
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
191+
with:
192+
name: nginx-agent-unsigned-snapshots
193+
path: build
194+
- name: Login to Docker Registry
195+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
196+
with:
197+
registry: ${{ secrets.REGISTRY_URL }}
198+
username: ${{ secrets.REGISTRY_USERNAME }}
199+
password: ${{ secrets.REGISTRY_PASSWORD }}
200+
- name: Run Integration Tests
201+
run: |
202+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }}
203+
CONTAINER_NGINX_IMAGE_REGISTRY="${{ secrets.REGISTRY_URL }}" \
204+
TAG="${{ matrix.container.plus }}-${{ matrix.container.image }}-${{ matrix.container.version }}" \
205+
OS_RELEASE="${{ matrix.container.release }}" OS_VERSION="${{ matrix.container.version }}" IMAGE_PATH="${{ matrix.container.path }}" \
206+
make official-image-integration-test
207207
208208
performance-tests:
209209
name: Performance Tests
@@ -312,9 +312,8 @@ jobs:
312312
if: ${{ github.ref_name == 'v3' &&
313313
!github.event.pull_request.head.repo.fork }}
314314
needs: [ lint, unit-test, performance-tests,
315-
load-tests,
316-
# official-oss-image-integration-tests,
317-
# official-plus-image-integration-tests,
315+
load-tests, official-oss-image-integration-tests,
316+
official-plus-image-integration-tests,
318317
race-condition-test, integration-tests ]
319318
uses: ./.github/workflows/release-branch.yml
320319
secrets: inherit

internal/command/command_service.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package command
88
import (
99
"context"
1010
"errors"
11+
"fmt"
1112
"log/slog"
1213
"sync"
1314
"sync/atomic"
@@ -408,11 +409,15 @@ func (cs *CommandService) receiveCallback(ctx context.Context) func() error {
408409
var err error
409410
cs.subscribeClient, err = cs.commandServiceClient.Subscribe(ctx)
410411
if err != nil {
411-
return cs.handleSubscribeError(ctx, err)
412+
subscribeErr := cs.handleSubscribeError(ctx, err, "create subscribe client")
413+
cs.subscribeClientMutex.Unlock()
414+
415+
return subscribeErr
412416
}
413417

414418
if cs.subscribeClient == nil {
415419
cs.subscribeClientMutex.Unlock()
420+
416421
return errors.New("subscribe service client not initialized yet")
417422
}
418423
}
@@ -421,10 +426,9 @@ func (cs *CommandService) receiveCallback(ctx context.Context) func() error {
421426

422427
request, recvError := cs.subscribeClient.Recv()
423428
if recvError != nil {
424-
slog.ErrorContext(ctx, "Failed to receive message from subscribe stream", "error", recvError)
425429
cs.subscribeClient = nil
426430

427-
return recvError
431+
return cs.handleSubscribeError(ctx, recvError, "receive message from subscribe stream")
428432
}
429433

430434
if cs.isValidRequest(ctx, request) {
@@ -440,23 +444,21 @@ func (cs *CommandService) receiveCallback(ctx context.Context) func() error {
440444
}
441445
}
442446

443-
func (cs *CommandService) handleSubscribeError(ctx context.Context, err error) error {
447+
func (cs *CommandService) handleSubscribeError(ctx context.Context, err error, errorMsg string) error {
444448
codeError, ok := status.FromError(err)
445449

446450
if ok && codeError.Code() == codes.Unavailable {
447-
slog.ErrorContext(ctx, "Failed to create subscribe client, rpc unavailable. "+
448-
"Trying create connection rpc", "error", err)
451+
slog.ErrorContext(ctx, fmt.Sprintf("Failed to %s, rpc unavailable. "+
452+
"Trying create connection rpc", errorMsg), "error", err)
449453
_, connectionErr := cs.CreateConnection(ctx, cs.resource)
450454
if connectionErr != nil {
451455
slog.ErrorContext(ctx, "Unable to create connection", "error", err)
452456
}
453-
cs.subscribeClientMutex.Unlock()
454457

455458
return nil
456459
}
457460

458-
slog.ErrorContext(ctx, "Failed to create subscribe client", "error", err)
459-
cs.subscribeClientMutex.Unlock()
461+
slog.ErrorContext(ctx, fmt.Sprintf("Failed to %s", errorMsg), "error", err)
460462

461463
return err
462464
}

0 commit comments

Comments
 (0)