Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workerId to TestCaseStarted #34

Merged
merged 12 commits into from
Oct 6, 2022
10 changes: 2 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- BREAKING CHANGE: Add `workerId` field to TestCaseStarted message ([#34](https://github.com/cucumber/messages/pull/34))
davidjgoss marked this conversation as resolved.
Show resolved Hide resolved

## [19.1.4] - 2022-09-22
### Changed
- Update dependencies

## [19.1.3] - 2022-09-20
### Added

### Changed

### Deprecated

### Fixed
- Add `name` field to `package.cjs.json` ([#36](https://github.com/cucumber/messages/pull/36))

### Removed

## [19.1.2] - 2022-06-22
### Fixed
- [Javascript] Schema was still missing in 19.1.1 due to how npm manages the files attribute in package.json
Expand Down
1 change: 1 addition & 0 deletions go/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ type TestCaseStarted struct {
Attempt int64 `json:"attempt"`
Id string `json:"id"`
TestCaseId string `json:"testCaseId"`
WorkerId string `json:"workerId,omitempty"`
Timestamp *Timestamp `json:"timestamp"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ public final class TestCaseStarted {
private final Long attempt;
private final String id;
private final String testCaseId;
private final String workerId;
private final Timestamp timestamp;

public TestCaseStarted(
Long attempt,
String id,
String testCaseId,
String workerId,
davidjgoss marked this conversation as resolved.
Show resolved Hide resolved
Timestamp timestamp
) {
this.attempt = requireNonNull(attempt, "TestCaseStarted.attempt cannot be null");
this.id = requireNonNull(id, "TestCaseStarted.id cannot be null");
this.testCaseId = requireNonNull(testCaseId, "TestCaseStarted.testCaseId cannot be null");
this.workerId = workerId;
this.timestamp = requireNonNull(timestamp, "TestCaseStarted.timestamp cannot be null");
}

Expand All @@ -39,6 +42,10 @@ public String getTestCaseId() {
return testCaseId;
}

public Optional<String> getWorkerId() {
return Optional.ofNullable(workerId);
}

public Timestamp getTimestamp() {
return timestamp;
}
Expand All @@ -52,6 +59,7 @@ public boolean equals(Object o) {
attempt.equals(that.attempt) &&
id.equals(that.id) &&
testCaseId.equals(that.testCaseId) &&
Objects.equals(workerId, that.workerId) &&
timestamp.equals(that.timestamp);
}

Expand All @@ -61,6 +69,7 @@ public int hashCode() {
attempt,
id,
testCaseId,
workerId,
timestamp
);
}
Expand All @@ -71,6 +80,7 @@ public String toString() {
"attempt=" + attempt +
", id=" + id +
", testCaseId=" + testCaseId +
", workerId=" + workerId +
", timestamp=" + timestamp +
'}';
}
Expand Down
2 changes: 2 additions & 0 deletions javascript/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ export class TestCaseStarted {

testCaseId: string = ''

workerId?: string

@Type(() => Timestamp)
timestamp: Timestamp = new Timestamp()
}
Expand Down
4 changes: 4 additions & 0 deletions jsonschema/TestCaseStarted.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"testCaseId": {
"type": "string"
},
"workerId": {
"description": "An identifier for the worker process running this test case, if test cases are being run in parallel. The identifier will be unique per worker, but no particular format is defined - it could be an index, uuid, machine name etc - and as such should be assumed that it's not human readable.",
"type": "string"
},
"timestamp": {
"$ref": "./Timestamp.json"
}
Expand Down
1 change: 1 addition & 0 deletions messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ will only have one of its fields set, which indicates the payload of the message
| `attempt` | integer | yes | |
| `id` | string | yes | |
| `testCaseId` | string | yes | |
| `workerId` | string | no | |
| `timestamp` | [Timestamp](#timestamp) | yes | |

## TestRunFinished
Expand Down
12 changes: 12 additions & 0 deletions perl/lib/Cucumber/Messages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4070,6 +4070,7 @@ my %types = (
attempt => 'number',
id => 'string',
test_case_id => 'string',
worker_id => 'string',
timestamp => 'Cucumber::Messages::Timestamp',
);

Expand Down Expand Up @@ -4123,6 +4124,17 @@ has test_case_id =>
);


=head4 worker_id

An identifier for the worker process running this test case, if test cases are being run in parallel. The identifier will be unique per worker, but no particular format is defined - it could be an index, uuid, machine name etc - and as such should be assumed that it's not human readable.

=cut

has worker_id =>
(is => 'ro',
);


=head4 timestamp


Expand Down
17 changes: 17 additions & 0 deletions php/src-generated/TestCaseStarted.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function __construct(
*/
public readonly string $id = '',
public readonly string $testCaseId = '',

/**
* An identifier for the worker process running this test case, if test cases are being run in parallel. The identifier will be unique per worker, but no particular format is defined - it could be an index, uuid, machine name etc - and as such should be assumed that it's not human readable.
*/
public readonly ?string $workerId = null,
public readonly Timestamp $timestamp = new Timestamp(),
) {
}
Expand All @@ -52,12 +57,14 @@ public static function fromArray(array $arr): self
self::ensureAttempt($arr);
self::ensureId($arr);
self::ensureTestCaseId($arr);
self::ensureWorkerId($arr);
self::ensureTimestamp($arr);

return new self(
(int) $arr['attempt'],
(string) $arr['id'],
(string) $arr['testCaseId'],
isset($arr['workerId']) ? (string) $arr['workerId'] : null,
Timestamp::fromArray($arr['timestamp']),
);
}
Expand Down Expand Up @@ -101,6 +108,16 @@ private static function ensureTestCaseId(array $arr): void
}
}

/**
* @psalm-assert array{workerId?: string|int|bool} $arr
*/
private static function ensureWorkerId(array $arr): void
{
if (array_key_exists('workerId', $arr) && is_array($arr['workerId'])) {
throw new SchemaViolationException('Property \'workerId\' was array');
}
}

/**
* @psalm-assert array{timestamp: array} $arr
*/
Expand Down
1 change: 1 addition & 0 deletions ruby/lib/cucumber/messages.deserializers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ def self.from_h(hash)
attempt: hash[:attempt],
id: hash[:id],
test_case_id: hash[:testCaseId],
worker_id: hash[:workerId],
timestamp: Timestamp.from_h(hash[:timestamp]),
)
end
Expand Down
7 changes: 7 additions & 0 deletions ruby/lib/cucumber/messages.dtos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1694,17 +1694,24 @@ class TestCaseStarted < ::Cucumber::Messages::Message

attr_reader :test_case_id

##
# An identifier for the worker process running this test case, if test cases are being run in parallel. The identifier will be unique per worker, but no particular format is defined - it could be an index, uuid, machine name etc - and as such should be assumed that it's not human readable.

attr_reader :worker_id

attr_reader :timestamp

def initialize(
attempt: 0,
id: '',
test_case_id: '',
worker_id: nil,
timestamp: Timestamp.new
)
@attempt = attempt
@id = id
@test_case_id = test_case_id
@worker_id = worker_id
@timestamp = timestamp
end
end
Expand Down