-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monitor: Refactor listener registration logic
- Modify registerNewListener() to take MonitorListener as a parameter to allow arbitrary listener to be registered instead of assuming the type of listener is always listenerv1_2. - Add Close() method to MonitorListener so that the Monitor can close listeners without knowing implementation details. - Explicitly call close() on listenerv1_2.queue so that drainQueue gets unblocked during unit test. Ref #9925 Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
- Loading branch information
1 parent
f5c42e7
commit 79cc0f3
Showing
4 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2018-2020 Authors of Cilium | ||
// | ||
// 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. | ||
|
||
// +build !privileged_tests | ||
|
||
package agent | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
. "gopkg.in/check.v1" | ||
|
||
"github.com/cilium/cilium/pkg/monitor/agent/listener" | ||
) | ||
|
||
func Test(t *testing.T) { TestingT(t) } | ||
|
||
type ListenerSuite struct{} | ||
|
||
var _ = Suite(&ListenerSuite{}) | ||
|
||
func (m *ListenerSuite) TestListenerv1_2(c *C) { | ||
closed := make(chan bool) | ||
server, client := net.Pipe() | ||
l := newListenerv1_2(client, 10, func(listener listener.MonitorListener) { | ||
closed <- true | ||
}) | ||
// Verify the listener version. | ||
c.Assert(l.Version(), Equals, listener.Version1_2) | ||
// Calling Close() multiple times shouldn't cause panic. | ||
l.Close() | ||
l.Close() | ||
// Make sure the cleanup function gets called. | ||
<-closed | ||
server.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters