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

[YUNIKORN-838] Improve coverage of allocation_ask.go #320

Merged
merged 3 commits into from Sep 14, 2021

Conversation

0yukali0
Copy link
Contributor

@0yukali0 0yukali0 commented Sep 7, 2021

What is this PR for?

Add unit test to improve coverage

What type of PR is it?

  • - Bug Fix
  • - Improvement
  • - Feature
  • - Documentation
  • - Hot Fix
  • - Refactoring

Todos

  • - Task

What is the Jira issue?

https://issues.apache.org/jira/browse/YUNIKORN-838

How should this be tested?

Use command "make test" to create coverage.txt and then use "go tool cover -func=coverage.txt" to check

Screenshots (if appropriate)

Questions:

  • - The licenses files need update.
  • - There is breaking changes for older versions.
  • - It needs documentation.

@codecov
Copy link

codecov bot commented Sep 7, 2021

Codecov Report

Merging #320 (9e40ef3) into master (5a1c19e) will increase coverage by 2.54%.
The diff coverage is 64.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #320      +/-   ##
==========================================
+ Coverage   63.46%   66.00%   +2.54%     
==========================================
  Files          60       63       +3     
  Lines        5220     5937     +717     
==========================================
+ Hits         3313     3919     +606     
- Misses       1747     1814      +67     
- Partials      160      204      +44     
Impacted Files Coverage Δ
pkg/metrics/init.go 62.96% <ø> (ø)
pkg/scheduler/drf_preemption_policy.go 0.00% <0.00%> (ø)
pkg/scheduler/nodes_usage_monitor.go 0.00% <0.00%> (ø)
pkg/scheduler/objects/allocation.go 100.00% <ø> (ø)
pkg/scheduler/objects/node_iterator.go 100.00% <ø> (ø)
pkg/scheduler/objects/sorters.go 100.00% <ø> (ø)
pkg/webservice/webservice.go 32.25% <ø> (+19.35%) ⬆️
pkg/scheduler/context.go 16.10% <23.33%> (+9.84%) ⬆️
pkg/metrics/metrics_collector.go 64.51% <45.00%> (-9.40%) ⬇️
pkg/metrics/scheduler.go 58.92% <49.33%> (-2.66%) ⬇️
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66cdb3d...9e40ef3. Read the comment docs.

@yangwwei
Copy link
Contributor

hi @0yukali0 sorry for the late response. I just looked more into this PR.
The priority actually has 2 forms, 1 is with the int value, the other is the priorityClass which is a string value, today the latter form is not fully implemented, but that's part of the proto, so it will be good to cover that as well. And regarding the UT itself, I think it can be simplified for easier reading. Below is what I thought in my mind, pls take a look:

func newPriorityValue(v int32) *si.Priority{
	return &si.Priority{
		Priority: &si.Priority_PriorityValue{
			PriorityValue: v},
	}
}

func newPriorityClass(priorityClassName string) *si.Priority {
	return &si.Priority{
		Priority: &si.Priority_PriorityClassName{
			PriorityClassName: priorityClassName},
	}
}

func TestSetPriority(t *testing.T) {
	var tests = []struct {
		testMessage           string
		priority              *si.Priority
		out                   int32
	}{
		// Set priorirty via NewAllocationAsk
		{"No priority setting",nil, 0},
		{"Set empty priority", &si.Priority{}, 0},
		{"Set positive priority value", newPriorityValue(1), 1},
		{"Set negative priority value", newPriorityValue(-100), -100},
		{"Set priority class", newPriorityClass("p0"), 0},
	}

	for _, tt := range tests {
		res := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10})
		t.Run(tt.testMessage, func(t *testing.T) {
			siAsk := &si.AllocationAsk{
				AllocationKey:  "ask-1",
				ApplicationID:  "app-1",
				MaxAllocations: 1,
				Priority:       tt.priority,
				ResourceAsk:    res.ToProto(),
			}

			ask := NewAllocationAsk(siAsk)
			if ask.priority != tt.out {
				t.Errorf("result %s, Want %v, got %v", tt.testMessage, tt.out, ask.priority)
			}
		})
	}
}

@0yukali0
Copy link
Contributor Author

Got it.

@yangwwei
Copy link
Contributor

@0yukali0 can u pls update the PR?

@0yukali0
Copy link
Contributor Author

0yukali0 commented Sep 13, 2021 via email

@0yukali0
Copy link
Contributor Author

Hi @yangwwei , setPriority funtion is not used in yunikorn-core now, should i add it into UT?
https://github.com/apache/incubator-yunikorn-core/blob/master/pkg/scheduler/objects/allocation_ask.go#L134-L138
image

Copy link
Contributor

@yangwwei yangwwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@yangwwei yangwwei merged commit 4533c13 into apache:master Sep 14, 2021
manirajv06 pushed a commit to manirajv06/incubator-yunikorn-core that referenced this pull request Sep 16, 2021
commit 98ad1a8
Author: Chia-Ping Tsai <chia7712@gmail.com>
Date:   Wed Sep 15 23:01:10 2021 +0800

    fix /ws/v1/queues

commit 50c85e2
Author: Chia-Ping Tsai <chia7712@gmail.com>
Date:   Wed Sep 15 14:00:07 2021 +0800

    use common helper directly

commit e9b88a8
Author: Chia-Ping Tsai <chia7712@gmail.com>
Date:   Tue Sep 14 19:25:02 2021 +0800

    [YUNIKORN-834] Unify the "partition name" in REST APIs

commit 4533c13
Author: 0yukali0 <45888688+0yukali0@users.noreply.github.com>
Date:   Tue Sep 14 11:16:27 2021 +0800

    [YUNIKORN-838] Improve coverage of allocation_ask.go (apache#320)

    Add UT coverage to the code sets priorities to allocation ask.

commit ab6fa20
Author: manirajv06 <manirajv06@gmail.com>
Date:   Tue Sep 14 02:46:40 2021 +0530

    [YUNIKORN-697]: Enforce partition name uniqueness in core (apache#321)
@0yukali0 0yukali0 deleted the YUNIKORN-838 branch June 14, 2023 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants