Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit 3507609

Browse files
authored
Merge pull request #3 from spiral/feature/do-not-close-channel
bug(channel): Do not close closed channel
2 parents 41d3e70 + 52981c3 commit 3507609

19 files changed

+267
-108
lines changed

.github/dependabot.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: gomod # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: daily
12+

.github/workflows/linux.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Linux
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
# Branches from forks have the form 'user:branch-name' so we only run
8+
# this job on pull_request events for branches that look like fork
9+
# branches. Without this we would end up running this job twice for non
10+
# forked PRs, once for the push and then once for opening the PR.
11+
- "**:**"
12+
13+
jobs:
14+
golang:
15+
name: Build (Go ${{ matrix.go }}, PHP ${{ matrix.php }}, OS ${{matrix.os}})
16+
runs-on: ${{ matrix.os }}
17+
timeout-minutes: 60
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php: [ "7.2","7.3", "7.4", "8.0" ]
22+
go: [ "1.14", "1.15" ]
23+
os: [ ubuntu-20.04 ]
24+
steps:
25+
- name: Set up Go ${{ matrix.go }}
26+
uses: actions/setup-go@v2 # action page: <https://github.com/actions/setup-go>
27+
with:
28+
go-version: ${{ matrix.go }}
29+
30+
- name: Set up PHP ${{ matrix.php }}
31+
uses: shivammathur/setup-php@v2 # action page: <https://github.com/shivammathur/setup-php>
32+
with:
33+
php-version: ${{ matrix.php }}
34+
extensions: sockets
35+
36+
- name: Check out code
37+
uses: actions/checkout@v2
38+
39+
- name: Get Composer Cache Directory
40+
id: composer-cache
41+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
42+
43+
- name: Init Composer Cache # Docs: <https://git.io/JfAKn#php---composer>
44+
uses: actions/cache@v2
45+
with:
46+
path: ${{ steps.composer-cache.outputs.dir }}
47+
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}
48+
restore-keys: ${{ runner.os }}-composer-
49+
50+
- name: Install Composer dependencies
51+
run: composer update --prefer-dist --no-progress --ansi
52+
53+
- name: Init Go modules Cache # Docs: <https://git.io/JfAKn#go---modules>
54+
uses: actions/cache@v2
55+
with:
56+
path: ~/go/pkg/mod
57+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
58+
restore-keys: ${{ runner.os }}-go-
59+
60+
- name: Install Go dependencies
61+
run: go mod download
62+
63+
- name: Run golang tests on Linux
64+
run: |
65+
mkdir ./coverage-ci
66+
go test -v -race -cover -coverpkg=./... -coverprofile=./coverage-ci/broadcast-ws.txt -covermode=atomic
67+
68+
- uses: codecov/codecov-action@v1 # Docs: <https://github.com/codecov/codecov-action>
69+
with:
70+
token: ${{ secrets.CODECOV_TOKEN }}
71+
file: ./coverage-ci/broadcast-ws.txt
72+
fail_ci_if_error: false
73+
74+
golangci-lint:
75+
name: Golang-CI (lint)
76+
runs-on: ubuntu-20.04
77+
steps:
78+
- name: Check out code
79+
uses: actions/checkout@v2
80+
81+
- name: Run linter
82+
uses: golangci/golangci-lint-action@v2 # Action page: <https://github.com/golangci/golangci-lint-action>
83+
with:
84+
version: v1.35 # without patch version
85+
only-new-issues: false # show only new issues if it's a pull request

.github/workflows/macos.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: macOS
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
# Branches from forks have the form 'user:branch-name' so we only run
8+
# this job on pull_request events for branches that look like fork
9+
# branches. Without this we would end up running this job twice for non
10+
# forked PRs, once for the push and then once for opening the PR.
11+
- "**:**"
12+
13+
jobs:
14+
golang:
15+
name: Build (Go ${{ matrix.go }}, PHP ${{ matrix.php }}, OS ${{matrix.os}})
16+
runs-on: ${{ matrix.os }}
17+
timeout-minutes: 60
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php: [ "7.2","7.3", "7.4", "8.0" ]
22+
go: [ "1.14", "1.15" ]
23+
os: [ macos-latest ]
24+
steps:
25+
- name: Set up Go ${{ matrix.go }}
26+
uses: actions/setup-go@v2 # action page: <https://github.com/actions/setup-go>
27+
with:
28+
go-version: ${{ matrix.go }}
29+
30+
- name: Set up PHP ${{ matrix.php }}
31+
uses: shivammathur/setup-php@v2 # action page: <https://github.com/shivammathur/setup-php>
32+
with:
33+
php-version: ${{ matrix.php }}
34+
extensions: sockets
35+
36+
- name: Check out code
37+
uses: actions/checkout@v2
38+
39+
- name: Get Composer Cache Directory
40+
id: composer-cache
41+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
42+
43+
- name: Init Composer Cache # Docs: <https://git.io/JfAKn#php---composer>
44+
uses: actions/cache@v2
45+
with:
46+
path: ${{ steps.composer-cache.outputs.dir }}
47+
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}
48+
restore-keys: ${{ runner.os }}-composer-
49+
50+
- name: Install Composer dependencies
51+
run: composer update --prefer-dist --no-progress --ansi
52+
53+
- name: Init Go modules Cache # Docs: <https://git.io/JfAKn#go---modules>
54+
uses: actions/cache@v2
55+
with:
56+
path: ~/go/pkg/mod
57+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
58+
restore-keys: ${{ runner.os }}-go-
59+
60+
- name: Install Go dependencies
61+
run: go mod download
62+
63+
- name: Run golang tests
64+
run: |
65+
mkdir ./coverage-ci
66+
go test -v -race -cover -coverpkg=./... -coverprofile=./coverage-ci/broadcast-ws.txt -covermode=atomic

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.idea
22
go.sum
3-
vendor
3+
vendor_php
44
composer.lock
55
.php_cs.cache
6-
tests/log.txt
6+
tests/log.txt

.travis.yml

-37
This file was deleted.

access_validator.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package ws
22

33
import (
44
"bytes"
5-
"github.com/spiral/roadrunner/service/http/attributes"
65
"io"
76
"net/http"
87
"strings"
8+
9+
"github.com/spiral/roadrunner/service/http/attributes"
910
)
1011

1112
type accessValidator struct {
@@ -31,7 +32,7 @@ func (w *accessValidator) copy(rw http.ResponseWriter) {
3132
}
3233
}
3334

34-
io.Copy(rw, w.buffer)
35+
_, _ = io.Copy(rw, w.buffer)
3536
}
3637

3738
// Header returns the header map that will be sent by WriteHeader.

access_validator_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package ws
22

33
import (
4-
"github.com/stretchr/testify/assert"
54
"testing"
5+
6+
"github.com/stretchr/testify/assert"
67
)
78

89
func TestResponseWrapper_Body(t *testing.T) {
910
w := newValidator()
10-
w.Write([]byte("hello"))
11+
_, _ =w.Write([]byte("hello"))
1112

1213
assert.Equal(t, []byte("hello"), w.Body())
1314
}

cmd/rr-ws/ws/debug.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package ws
22

33
import (
4+
"strings"
5+
46
"github.com/gorilla/websocket"
57
"github.com/sirupsen/logrus"
68
"github.com/spf13/cobra"
79
ws "github.com/spiral/broadcast-ws"
810
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
911
"github.com/spiral/roadrunner/cmd/util"
10-
"strings"
1112
)
1213

1314
func init() {

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"email": "wolfy.jd@gmail.com"
1010
}
1111
],
12+
"config": {
13+
"vendor-dir": "vendor_php"
14+
},
1215
"require": {
1316
"php": ">=7.2",
1417
"ext-json": "*",

config_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package ws
22

33
import (
44
"encoding/json"
5+
"testing"
6+
57
"github.com/spiral/roadrunner/service"
68
"github.com/stretchr/testify/assert"
7-
"testing"
89
)
910

1011
type mockCfg struct{ cfg string }

conn_context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package ws
22

33
import (
44
"encoding/json"
5+
56
"github.com/gorilla/websocket"
6-
"github.com/spiral/broadcast"
7+
"github.com/spiral/broadcast/v2"
78
)
89

910
// ConnContext carries information about websocket connection and it's topics.

conn_context_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package ws
22

33
import (
4-
"github.com/stretchr/testify/assert"
54
"testing"
5+
6+
"github.com/stretchr/testify/assert"
67
)
78

89
func TestConnContext_ManageTopics(t *testing.T) {

conn_pool.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package ws
22

33
import (
44
"errors"
5-
"github.com/gorilla/websocket"
6-
"github.com/spiral/broadcast"
75
"sync"
6+
7+
"github.com/gorilla/websocket"
8+
"github.com/spiral/broadcast/v2"
89
)
910

1011
// manages a set of websocket connections
@@ -71,7 +72,6 @@ func (cp *connPool) disconnect(conn *websocket.Conn) error {
7172
}
7273

7374
delete(cp.conns, conn)
74-
close(ctx.upstream)
7575

7676
return conn.Close()
7777
}
@@ -117,7 +117,7 @@ func (cp *connPool) close() {
117117
}
118118

119119
delete(cp.conns, conn)
120-
close(ctx.upstream)
120+
121121
if err := conn.Close(); err != nil {
122122
cp.errHandler(err, conn)
123123
}

go.mod

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module github.com/spiral/broadcast-ws
22

3-
go 1.12
3+
go 1.15
44

55
require (
6-
github.com/gorilla/websocket v1.4.1
7-
github.com/prometheus/client_golang v1.2.1 // indirect
8-
github.com/sirupsen/logrus v1.4.2
9-
github.com/spf13/cobra v0.0.5 // indirect
10-
github.com/spiral/broadcast v0.0.0-20191206140608-766959683e74
11-
github.com/spiral/roadrunner v1.5.2
12-
github.com/stretchr/testify v1.3.0
6+
github.com/gorilla/websocket v1.4.2
7+
github.com/prometheus/client_golang v1.7.1
8+
github.com/sirupsen/logrus v1.6.0
9+
github.com/spf13/cobra v1.0.0
10+
github.com/spiral/broadcast/v2 v2.0.5
11+
github.com/spiral/roadrunner v1.9.2
12+
github.com/stretchr/testify v1.6.1
1313
)

service.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package ws
22

33
import (
44
"encoding/json"
5+
"net/http"
6+
"sync"
7+
"sync/atomic"
8+
59
"github.com/gorilla/websocket"
6-
"github.com/spiral/broadcast"
10+
"github.com/spiral/broadcast/v2"
711
"github.com/spiral/roadrunner/service/env"
812
rhttp "github.com/spiral/roadrunner/service/http"
913
"github.com/spiral/roadrunner/service/rpc"
10-
"net/http"
11-
"sync"
12-
"sync/atomic"
1314
)
1415

1516
// ID defines service id.

0 commit comments

Comments
 (0)