Skip to content

Commit

Permalink
use buffered channel for signal notifications (#471)
Browse files Browse the repository at this point in the history
Signed-off-by: SataQiu <[email protected]>
  • Loading branch information
SataQiu authored and YRXING committed Sep 15, 2021
1 parent 2c9e1dc commit af2f3db
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 140 deletions.
5 changes: 4 additions & 1 deletion cmd/yurt-tunnel-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func main() {
klog.InitFlags(nil)
defer klog.Flush()

s := make(chan os.Signal)
// Set up channel on which to send signal notifications.
// We must use a buffered channel or risk missing the signal
// if we're not ready to receive when the signal is sent.
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM,
syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, syscall.SIGABRT)
stop := make(chan struct{})
Expand Down
22 changes: 19 additions & 3 deletions pkg/profile/profile_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2021 The OpenYurt Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package profile

import (
Expand All @@ -6,16 +22,16 @@ import (
"testing"
)

func fakeServer(h http.Handler) error{
err := http.ListenAndServe(":9090",h)
func fakeServer(h http.Handler) error {
err := http.ListenAndServe(":9090", h)
return err
}

func TestInstall(t *testing.T) {
m := mux.NewRouter()
Install(m)
go fakeServer(m)
r,err := http.Get("http://localhost:9090/debug/pprof/")
r, err := http.Get("http://localhost:9090/debug/pprof/")
if err != nil {
t.Error(" failed to send request to fake server")
}
Expand Down
Loading

0 comments on commit af2f3db

Please sign in to comment.