Skip to content

Commit

Permalink
Add async counter for unittest (#711)
Browse files Browse the repository at this point in the history
* add async counter helper

* extend-http-dumper-ut-time
  • Loading branch information
EvanLjp authored Mar 21, 2023
1 parent dd505f1 commit 59f30fc
Show file tree
Hide file tree
Showing 40 changed files with 632 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 iLogtail 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.

FROM sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail-community-edition/ilogtail-build-linux:latest

ARG USERNAME=admin
Expand Down
14 changes: 14 additions & 0 deletions helper/container_export_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 helper

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/decoder/pyroscope/decoder.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 pyroscope

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/decoder/pyroscope/decoder_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 pyroscope

import (
Expand Down
34 changes: 34 additions & 0 deletions helper/dumper.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 helper

import (
Expand All @@ -13,6 +27,7 @@ import (

"github.com/alibaba/ilogtail/pkg/logger"
"github.com/alibaba/ilogtail/pkg/util"
"github.com/alibaba/ilogtail/plugins/test/async"
)

type DumpDataReq struct {
Expand All @@ -38,6 +53,8 @@ type Dumper struct {
maxKeepFiles int
wg sync.WaitGroup
stop chan struct{}
// unittest
writeCounter *async.UnitTestCounterHelper
}

func (d *Dumper) Init() {
Expand Down Expand Up @@ -109,6 +126,7 @@ func (d *Dumper) doDumpFile() {
}
}
if f != nil {
d.AddDelta(1)
buffer := bytes.NewBuffer([]byte{})
b, _ := json.Marshal(data)
if err = binary.Write(buffer, binary.BigEndian, uint32(len(b))); err != nil {
Expand Down Expand Up @@ -138,3 +156,19 @@ func NewDumper(prefix string, maxFiles int) *Dumper {
maxKeepFiles: maxFiles,
}
}

func (d *Dumper) Begin(callback func()) bool {
d.writeCounter = new(async.UnitTestCounterHelper)
d.writeCounter.Begin(callback)
return true
}

func (d *Dumper) End(timeout time.Duration, expectNum int64) error {
return d.writeCounter.End(timeout, expectNum)
}

func (d *Dumper) AddDelta(num int64) {
if d.writeCounter != nil {
d.writeCounter.AddDelta(num)
}
}
20 changes: 18 additions & 2 deletions helper/dumper_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 helper

import (
Expand Down Expand Up @@ -77,8 +91,9 @@ func TestServiceHTTP_doDumpFile(t *testing.T) {
s.Init()
ch = s.InputChannel()
s.Start()
s.Begin(func() {})
insertFun(100, 0)
time.Sleep(time.Millisecond * 100)
require.NoError(t, s.End(time.Second*2, 100))
s.Close()
readFunc(s.dumpDataKeepFiles[len(s.dumpDataKeepFiles)-1], 100)

Expand All @@ -87,8 +102,9 @@ func TestServiceHTTP_doDumpFile(t *testing.T) {
s2.Init()
ch = s2.InputChannel()
s2.Start()
s2.Begin(func() {})
insertFun(100, 100)
time.Sleep(time.Millisecond * 100)
require.NoError(t, s2.End(time.Second*2, 100))
s2.Close()
readFunc(s.dumpDataKeepFiles[len(s.dumpDataKeepFiles)-1], 200)
}
14 changes: 14 additions & 0 deletions helper/k8s.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 helper

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/k8s_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 helper

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/path_helper_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 helper

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/platformmeta/aliyun_ecs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 platformmeta

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/platformmeta/interface.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 platformmeta

const (
Expand Down
14 changes: 14 additions & 0 deletions helper/platformmeta/mock.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 platformmeta

import "sync/atomic"
Expand Down
14 changes: 14 additions & 0 deletions helper/profile/meta.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 Down
14 changes: 14 additions & 0 deletions helper/profile/meta_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 Down
14 changes: 14 additions & 0 deletions helper/profile/pyroscope/jfr/jfr.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 jfr

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/profile/pyroscope/jfr/jfr_labels.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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.

syntax = "proto3";

//package io.pyroscope.labels.pb;
Expand Down
14 changes: 14 additions & 0 deletions helper/profile/pyroscope/jfr/jfr_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 jfr

import (
Expand Down
14 changes: 14 additions & 0 deletions helper/profile/pyroscope/jfr/parser.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 iLogtail 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 jfr

import (
Expand Down
Loading

0 comments on commit 59f30fc

Please sign in to comment.