Skip to content

Commit

Permalink
Add Concurrency Tests for Array Operations (#985)
Browse files Browse the repository at this point in the history
A. Total Tests: 49 cases(7*7)

Initially, the symmetric relationship between clients in operation
combinations was not included. However, since the Lamport clock
comparison varies depending on the client ID, the tests were modified
to check all cases.

B. Operations per Client: 7(2+3+1+1)
- Insert: 2 cases(Prev, Prev.Next)
- Move: 3 cases(Prev, Prev.Next, Target)
- Set: 1 case(Target)
- Remove: 1 case(Target)

C. Failure Cases: 10 cases(2*2 + 2 + 1*2 + 1*2)

1. *.Prev == Move.Target 4 cases(2*2, symmetric)
  - Insert.Prev == Move.Target
  - Move.Prev == Move.Target
2. *.Prev.Next == Set.Target: 2 cases(asymmetric)
  - Insert.Prev.Next == Set.Target
  - Move.Prev.Next == Set.Target
3. Move.Target == Set.Target: 2 cases(1*2, symmetric, client ID matters)
4. Remove.Target == Set.Target: 2 cases (1*2, symmetric)
  • Loading branch information
cloneot authored Sep 2, 2024
1 parent 800f139 commit 256bf02
Show file tree
Hide file tree
Showing 12 changed files with 1,382 additions and 765 deletions.
27 changes: 27 additions & 0 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ func FromOperations(pbOps []*api.Operation) ([]operations.Operation, error) {
op, err = fromTreeEdit(decoded.TreeEdit)
case *api.Operation_TreeStyle_:
op, err = fromTreeStyle(decoded.TreeStyle)
case *api.Operation_SetByIndex_:
op, err = fromSetByIndex(decoded.SetByIndex)
default:
return nil, ErrUnsupportedOperation
}
Expand Down Expand Up @@ -539,6 +541,31 @@ func fromTreeStyle(pbTreeStyle *api.Operation_TreeStyle) (*operations.TreeStyle,
), nil
}

func fromSetByIndex(pbSetByIndex *api.Operation_SetByIndex) (*operations.SetByIndex, error) {
parentCreatedAt, err := fromTimeTicket(pbSetByIndex.ParentCreatedAt)
if err != nil {
return nil, err
}
createdAt, err := fromTimeTicket(pbSetByIndex.CreatedAt)
if err != nil {
return nil, err
}
elem, err := fromElement(pbSetByIndex.Value)
if err != nil {
return nil, err
}
executedAt, err := fromTimeTicket(pbSetByIndex.ExecutedAt)
if err != nil {
return nil, err
}
return operations.NewSetByIndex(
parentCreatedAt,
createdAt,
elem,
executedAt,
), nil
}

func fromCreatedAtMapByActor(
pbCreatedAtMapByActor map[string]*api.TimeTicket,
) (map[string]*time.Ticket, error) {
Expand Down
18 changes: 18 additions & 0 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func ToOperations(ops []operations.Operation) ([]*api.Operation, error) {
pbOperation.Body, err = toTreeEdit(op)
case *operations.TreeStyle:
pbOperation.Body, err = toTreeStyle(op)
case *operations.SetByIndex:
pbOperation.Body, err = toSetByIndex(op)
default:
return nil, ErrUnsupportedOperation
}
Expand Down Expand Up @@ -375,6 +377,22 @@ func toTreeStyle(style *operations.TreeStyle) (*api.Operation_TreeStyle_, error)
}, nil
}

func toSetByIndex(setByIndex *operations.SetByIndex) (*api.Operation_SetByIndex_, error) {
pbElem, err := toJSONElementSimple(setByIndex.Value())
if err != nil {
return nil, err
}

return &api.Operation_SetByIndex_{
SetByIndex: &api.Operation_SetByIndex{
ParentCreatedAt: ToTimeTicket(setByIndex.ParentCreatedAt()),
CreatedAt: ToTimeTicket(setByIndex.CreatedAt()),
Value: pbElem,
ExecutedAt: ToTimeTicket(setByIndex.ExecutedAt()),
},
}, nil
}

func toJSONElementSimple(elem crdt.Element) (*api.JSONElementSimple, error) {
switch elem := elem.(type) {
case *crdt.Object:
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/admin.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,12 @@ components:
description: ""
title: set
type: object
setByIndex:
$ref: '#/components/schemas/yorkie.v1.Operation.SetByIndex'
additionalProperties: false
description: ""
title: set_by_index
type: object
style:
$ref: '#/components/schemas/yorkie.v1.Operation.Style'
additionalProperties: false
Expand Down Expand Up @@ -1476,6 +1482,36 @@ components:
type: object
title: Set
type: object
yorkie.v1.Operation.SetByIndex:
additionalProperties: false
description: 'NOTE(junseo): `value.created_at` is set to same as `created_at`'
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: SetByIndex
type: object
yorkie.v1.Operation.Style:
additionalProperties: false
description: ""
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/resources.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,12 @@ components:
description: ""
title: set
type: object
setByIndex:
$ref: '#/components/schemas/yorkie.v1.Operation.SetByIndex'
additionalProperties: false
description: ""
title: set_by_index
type: object
style:
$ref: '#/components/schemas/yorkie.v1.Operation.Style'
additionalProperties: false
Expand Down Expand Up @@ -985,6 +991,36 @@ components:
type: object
title: Set
type: object
yorkie.v1.Operation.SetByIndex:
additionalProperties: false
description: 'NOTE(junseo): `value.created_at` is set to same as `created_at`'
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: SetByIndex
type: object
yorkie.v1.Operation.Style:
additionalProperties: false
description: ""
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/yorkie.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,12 @@ components:
description: ""
title: set
type: object
setByIndex:
$ref: '#/components/schemas/yorkie.v1.Operation.SetByIndex'
additionalProperties: false
description: ""
title: set_by_index
type: object
style:
$ref: '#/components/schemas/yorkie.v1.Operation.Style'
additionalProperties: false
Expand Down Expand Up @@ -969,6 +975,36 @@ components:
type: object
title: Set
type: object
yorkie.v1.Operation.SetByIndex:
additionalProperties: false
description: 'NOTE(junseo): `value.created_at` is set to same as `created_at`'
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: SetByIndex
type: object
yorkie.v1.Operation.Style:
additionalProperties: false
description: ""
Expand Down
Loading

0 comments on commit 256bf02

Please sign in to comment.