-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Increase reading buffer size on large messages (#74) When larger than MaxBufferSize messages are being sent, the whole message processing is failing badly. This can easily happen when socket plugin is used in Ceilometer metrics or events processing. Resolves: rhbz#2016460 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2016460 (cherry picked from commit f13e241) (cherry picked from commit 4af768f) * Ci opstools fix (#85) (#88) (#90) * Fix centos-opstools repo in CI * Update .github/workflows/integration.yml Co-authored-by: Leif Madsen <[email protected]> Co-authored-by: Matthias Runge <[email protected]> (cherry picked from commit 04fc691) (cherry picked from commit 63f8c2c) (cherry picked from commit ecd07f5) Co-authored-by: Martin Mágr <[email protected]> Co-authored-by: Leif Madsen <[email protected]>
- Loading branch information
1 parent
ecd07f5
commit 0120e4c
Showing
2 changed files
with
103 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"net" | ||
"os" | ||
"path" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/infrawatch/apputils/logging" | ||
"github.com/stretchr/testify/require" | ||
"gopkg.in/go-playground/assert.v1" | ||
) | ||
|
||
const regularBuffSize = 16384 | ||
|
||
func TestSocketTransport(t *testing.T) { | ||
tmpdir, err := ioutil.TempDir(".", "socket_test_tmp") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpdir) | ||
|
||
logpath := path.Join(tmpdir, "test.log") | ||
logger, err := logging.NewLogger(logging.DEBUG, logpath) | ||
require.NoError(t, err) | ||
|
||
sktpath := path.Join(tmpdir, "socket") | ||
skt, err := os.OpenFile(sktpath, os.O_RDWR|os.O_CREATE, os.ModeSocket|os.ModePerm) | ||
require.NoError(t, err) | ||
defer skt.Close() | ||
|
||
trans := Socket{ | ||
conf: configT{ | ||
Path: sktpath, | ||
}, | ||
logger: &logWrapper{ | ||
l: logger, | ||
}, | ||
} | ||
|
||
t.Run("test large message transport", func(t *testing.T) { | ||
msg := make([]byte, regularBuffSize) | ||
addition := "wubba lubba dub dub" | ||
for i := 0; i < regularBuffSize; i++ { | ||
msg[i] = byte('X') | ||
} | ||
msg[regularBuffSize-1] = byte('$') | ||
msg = append(msg, []byte(addition)...) | ||
|
||
// verify transport | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
wg := sync.WaitGroup{} | ||
go trans.Run(ctx, func(mess []byte) { | ||
wg.Add(1) | ||
strmsg := string(mess) | ||
assert.Equal(t, regularBuffSize+len(addition), len(strmsg)) // we received whole message | ||
assert.Equal(t, addition, strmsg[len(strmsg)-len(addition):]) // and the out-of-band part is correct | ||
wg.Done() | ||
}, make(chan bool)) | ||
|
||
// wait for socket file to be created | ||
for { | ||
stat, err := os.Stat(sktpath) | ||
require.NoError(t, err) | ||
if stat.Mode()&os.ModeType == os.ModeSocket { | ||
break | ||
} | ||
time.Sleep(250 * time.Millisecond) | ||
} | ||
|
||
// write to socket | ||
wskt, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: sktpath, Net: "unixgram"}) | ||
require.NoError(t, err) | ||
_, err = wskt.Write(msg) | ||
require.NoError(t, err) | ||
|
||
cancel() | ||
wg.Wait() | ||
wskt.Close() | ||
}) | ||
} |