Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
goshacodes authored Jan 2, 2025
2 parents d087755 + 3c91835 commit 9805d2d
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 54 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release
on:
push:
tags: ["*"]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
java-version: 8
distribution: 'adopt'
cache: sbt
- uses: sbt/setup-sbt@v1
- run: sbt ci-release
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
5 changes: 2 additions & 3 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ on:

jobs:
scala_3:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'adopt'
- uses: sbt/setup-sbt@v1
- name: Run tests
run: sbt ++3.4.2 test
15 changes: 15 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,18 @@ lazy val examples = project in file("examples") settings(
specs2.value % Test
)
) dependsOn scalamock.jvm

inThisBuild(
List(
organization := "org.scalamock",
homepage := Some(url("http://scalamock.org/")),
licenses := List(
"MIT" -> url("https://opensource.org/licenses/MIT")
),
developers := List(
Developer("paulbutcher", "Paul Butcher", "", url("http://paulbutcher.com/")),
Developer("barkhorn", "Philipp Meyerhoefer", "", url("https://github.com/barkhorn")),
Developer("goshacodes", "Georgii Kovalev", "", url("https://github.com/goshacodes"))
)
)
)
60 changes: 51 additions & 9 deletions jvm/src/test/scala/org/scalamock/test/specs2/ConcurrencyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,24 @@

package org.scalamock.test.specs2

import scala.concurrent.Await
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.concurrent.duration.SECONDS

import org.scalamock.specs2.MockContext
import scala.concurrent.duration.{Duration, SECONDS}
import org.scalamock.specs2.IsolatedMockFactory
import org.scalamock.test.mockable.TestTrait
import org.specs2.mutable.Specification

class ConcurrencyTest extends Specification {
class ConcurrencyTest extends Specification with IsolatedMockFactory {

"Futures should work" in new MockContext {
"Futures should work" in {
val s = stubFunction[Int]
s.when().returns(1)
Await.result(Future { s() }, Duration(10, SECONDS)) must be_==(1)
s.verify().once()
success
}

"Concurrent mock access should work" in new MockContext {
"Concurrent mock access should work" in {
val m = mock[TestTrait]
(m.oneParamMethod _).expects(42).repeated(500000).returning("a")

Expand All @@ -48,5 +46,49 @@ class ConcurrencyTest extends Specification {
}

futures.foreach(future => Await.result(future, Duration(10, SECONDS)))
success
}

case class MyClass(i: Int)

trait SlowTestTrait {
def oneParamMethod(param: MyClass): String
def otherMethod(): String
}

val m1 = stub[SlowTestTrait]
// This test fails flakily, so rerun it several times to confirm.
(1 to 10).foreach(i =>
s"Concurrent mock access should work ($i)" in {
val len = 500
val args = (0 to len).toList
(m1.otherMethod _).when().returns("ok")
args.foreach(i => (m1.oneParamMethod _).when(MyClass(i)).returns(i.toString))

val futures = args.map { i =>
Future {
m1.oneParamMethod(MyClass(i))
}
}

futures.foreach(future => Await.result(future, Duration(10, SECONDS)))
args.foreach { i =>
Future {
m1.otherMethod()
}
}
args.foreach { i =>
Future {
m1.oneParamMethod(MyClass(i))
}
}

eventually {
(1 to len).foreach { i =>
(m1.oneParamMethod _).verify(MyClass(i)).atLeastOnce()
}
success
}
})

}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.8
sbt.version=1.10.7
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
addSbtPlugin("com.github.sbt" % "sbt-git" % "2.1.0")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
Expand Down
37 changes: 0 additions & 37 deletions publishing.sbt

This file was deleted.

4 changes: 2 additions & 2 deletions shared/src/main/scala/org/scalamock/context/CallLog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ private[scalamock] class CallLog {
log += call
}

def foreach(f: Call => Unit) = log foreach f
def foreach(f: Call => Unit) = this.synchronized { log foreach f }

override def toString = log mkString(" ", "\n ", "")
override def toString = this.synchronized { log mkString(" ", "\n ", "") }

private val log = new ListBuffer[Call]
}

0 comments on commit 9805d2d

Please sign in to comment.