Skip to content

Commit

Permalink
Add an example that shows how to use the cpu:<num> tag for tests.
Browse files Browse the repository at this point in the history
Also serves as an example for bug bazelbuild#3106.

PiperOrigin-RevId: 158116940
  • Loading branch information
philwo authored and katre committed Jun 6, 2017
1 parent 7e7d94e commit a2194e5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/java-native/src/test/java/com/example/myproject/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ java_test(
deps = ["//third_party:junit4"],
)

# This exercises the "cpu:<num>" tag.
#
# Expected behavior:
# test0 and test1 run together then one of the other two alone, and then the remaining one alone.
java_test(
name = "sleep0",
srcs = ["TestSleep.java"],
test_class = "com.example.myproject.TestSleep",
deps = ["//third_party:junit4"],
)

java_test(
name = "sleep1",
srcs = ["TestSleep.java"],
test_class = "com.example.myproject.TestSleep",
deps = ["//third_party:junit4"],
)

java_test(
name = "sleep2",
srcs = ["TestSleep.java"],
tags = ["cpu:20000"],
test_class = "com.example.myproject.TestSleep",
deps = ["//third_party:junit4"],
)

java_test(
name = "sleep3",
srcs = ["TestSleep.java"],
tags = ["cpu:20000"],
test_class = "com.example.myproject.TestSleep",
deps = ["//third_party:junit4"],
)

# This attempts to run TestCustomGreeting.java without any resources, so fails.
java_test(
name = "resource-fail",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.myproject;

import org.junit.Test;

/** Contains a single test that just sleeps for 15 seconds and then succeeds. */
public class TestSleep {
@Test
public void testSleep() throws Exception {
// Sleep for 15 seconds.
Thread.sleep(15 * 1000);
}
}

0 comments on commit a2194e5

Please sign in to comment.