-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial k6/execution module with VU stats
Part of #1320
- Loading branch information
Ivan Mirić
committed
Jun 16, 2021
1 parent
9b8a963
commit 8292ef7
Showing
4 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2021 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package execution | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"go.k6.io/k6/lib" | ||
) | ||
|
||
// Execution is a JS module to return information about the execution in progress. | ||
type Execution struct{} | ||
|
||
// New returns a pointer to a new Execution. | ||
func New() *Execution { | ||
return &Execution{} | ||
} | ||
|
||
// GetVUStats returns information about the currently executing VU. | ||
func (e *Execution) GetVUStats(ctx context.Context) (map[string]interface{}, error) { | ||
vuState := lib.GetState(ctx) | ||
if vuState == nil { | ||
return nil, errors.New("VU information can only be returned from an exported function") | ||
} | ||
|
||
out := map[string]interface{}{ | ||
"id": vuState.Vu, | ||
"iteration": vuState.Iteration, | ||
} | ||
|
||
return out, nil | ||
} |
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