forked from TrueCloudLab/xk6-frostfs
Monitor VU cancel
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
96e0e0188e
commit
9c866ca6e1
2 changed files with 20 additions and 0 deletions
|
@ -58,6 +58,9 @@ func (c *Client) Put(bucket, key string, payload goja.ArrayBuffer) PutResponse {
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
ch := CancelMonitor(c.vu.Context(), c.vu.State().Logger.WithField("method", "put"))
|
||||||
|
defer func() { close(ch) }()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), c.to)
|
ctx, cancel := context.WithTimeout(context.Background(), c.to)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -136,6 +139,9 @@ func (c *Client) Delete(bucket, key string) DeleteResponse {
|
||||||
func (c *Client) Get(bucket, key string) GetResponse {
|
func (c *Client) Get(bucket, key string) GetResponse {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
ch := CancelMonitor(c.vu.Context(), c.vu.State().Logger.WithField("method", "get"))
|
||||||
|
defer func() { close(ch) }()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), c.to)
|
ctx, cancel := context.WithTimeout(context.Background(), c.to)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package s3
|
package s3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -10,6 +11,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/config"
|
"github.com/aws/aws-sdk-go-v2/config"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"go.k6.io/k6/js/modules"
|
"go.k6.io/k6/js/modules"
|
||||||
"go.k6.io/k6/metrics"
|
"go.k6.io/k6/metrics"
|
||||||
)
|
)
|
||||||
|
@ -117,3 +119,15 @@ func (s *S3) Connect(endpoint string, params map[string]string) (*Client, error)
|
||||||
to: timeout,
|
to: timeout,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CancelMonitor(ctx context.Context, writer logrus.FieldLogger) chan<- struct{} {
|
||||||
|
ch := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
writer.WithField("error", ctx.Err()).Print("VU context done")
|
||||||
|
case <-ch:
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue