-
Notifications
You must be signed in to change notification settings - Fork 3
Unit Testing core service BlockPoolService #739
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
170e973
NewBlockPoolService, GetBlocks, GetBlock, InsertBlock, ClearBlockPool
nawikart c156467
Merge branch 'develop' into Unit-Test-core-service-blockPoolService
andy-shi88 92e3e92
add assertion
nawikart e8c2dce
Merge branch 'develop' of ssh://github.com/zoobc/zoobc-core into Unit…
nawikart ba9e071
Merge branch 'Unit-Test-core-service-blockPoolService' of ssh://githu…
nawikart 6e6bac3
gofmt -s -w
nawikart 76794a1
Merge branch 'develop' into Unit-Test-core-service-blockPoolService
andy-shi88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,177 @@ | ||
package service | ||
|
||
import ( | ||
"reflect" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/zoobc/zoobc-core/common/model" | ||
) | ||
|
||
func TestNewBlockPoolService(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want *BlockPoolService | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "NewBlockPoolService:success", | ||
want: &BlockPoolService{ | ||
BlockQueue: make(map[int64]*model.Block), | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := NewBlockPoolService(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("NewBlockPoolService() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBlockPoolService_GetBlocks(t *testing.T) { | ||
type fields struct { | ||
BlockQueueLock sync.RWMutex | ||
BlockQueue map[int64]*model.Block | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want map[int64]*model.Block | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "GetBlocks:success", | ||
fields: fields{ | ||
// BlockQueueLock: sync.RWMutex, | ||
BlockQueue: map[int64]*model.Block{ | ||
0: {}, | ||
}, | ||
}, | ||
want: map[int64]*model.Block{ | ||
0: {}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
bps := &BlockPoolService{ | ||
BlockQueueLock: tt.fields.BlockQueueLock, | ||
BlockQueue: tt.fields.BlockQueue, | ||
} | ||
if got := bps.GetBlocks(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("BlockPoolService.GetBlocks() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBlockPoolService_GetBlock(t *testing.T) { | ||
type fields struct { | ||
BlockQueueLock sync.RWMutex | ||
BlockQueue map[int64]*model.Block | ||
} | ||
type args struct { | ||
index int64 | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *model.Block | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "GetBlock:success", | ||
fields: fields{ | ||
BlockQueue: map[int64]*model.Block{ | ||
0: {}, | ||
}, | ||
}, | ||
want: &model.Block{}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
bps := &BlockPoolService{ | ||
BlockQueueLock: tt.fields.BlockQueueLock, | ||
BlockQueue: tt.fields.BlockQueue, | ||
} | ||
if got := bps.GetBlock(tt.args.index); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("BlockPoolService.GetBlock() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBlockPoolService_InsertBlock(t *testing.T) { | ||
type fields struct { | ||
BlockQueueLock sync.RWMutex | ||
BlockQueue map[int64]*model.Block | ||
} | ||
type args struct { | ||
block *model.Block | ||
index int64 | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "InsertBlock:success", | ||
fields: fields{ | ||
BlockQueue: map[int64]*model.Block{ | ||
0: {}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
bps := &BlockPoolService{ | ||
BlockQueueLock: tt.fields.BlockQueueLock, | ||
BlockQueue: tt.fields.BlockQueue, | ||
} | ||
bps.InsertBlock(tt.args.block, tt.args.index) | ||
if got := bps.GetBlock(tt.args.index); !reflect.DeepEqual(got, tt.fields.BlockQueue[tt.args.index]) { | ||
t.Errorf("BlockPoolService.InsertBlock() = %v, want %v", got, tt.fields.BlockQueue[tt.args.index]) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBlockPoolService_ClearBlockPool(t *testing.T) { | ||
type fields struct { | ||
BlockQueueLock sync.RWMutex | ||
BlockQueue map[int64]*model.Block | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "ClearBlockPool:success", | ||
fields: fields{ | ||
BlockQueue: map[int64]*model.Block{ | ||
0: {}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
bps := &BlockPoolService{ | ||
BlockQueueLock: tt.fields.BlockQueueLock, | ||
BlockQueue: tt.fields.BlockQueue, | ||
} | ||
bps.ClearBlockPool() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there should be assertion here checking the blockpool cleared correctly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just updated, pls check again ya @capt4ce |
||
if len(tt.fields.BlockQueue) > 0 { | ||
t.Errorf("BlockPoolService.ClearBlockPool() = %v, want %v", tt.fields.BlockQueue, make(map[int64]*model.Block)) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be assertion here to check whether the blocks is inserted correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just updated, pls check again ya @capt4ce