Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Fix bug: lock wrong dependency when installing
Browse files Browse the repository at this point in the history
  • Loading branch information
blindpirate committed Mar 23, 2017
1 parent fbc569a commit 7e4a552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private ResolvedDependency resolveVcs(NotationDependency dependency, File vcsRoo
@Override
public void install(ResolvedDependency dependency, File targetDirectory) {
try {
globalCacheManager.runWithGlobalCacheLock(dependency, () -> {
ResolvedDependency realDependency = determineResolvedDependency(dependency);
globalCacheManager.runWithGlobalCacheLock(realDependency, () -> {
installUnderLock(dependency, targetDirectory);
return null;
});
Expand All @@ -108,7 +109,6 @@ public void install(ResolvedDependency dependency, File targetDirectory) {
}
}


private void installUnderLock(ResolvedDependency dependency, File targetDirectory) {
ResolvedDependency realDependency = determineResolvedDependency(dependency);
Path globalCachePath = globalCacheManager.getGlobalPackageCachePath(realDependency.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.github.blindpirate.gogradle.util.IOUtils
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.Mock
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
Expand Down Expand Up @@ -170,6 +171,17 @@ class AbstractVcsDependencyManagerTest {
verify(cacheManager).updateCurrentDependencyLock()
}

@Test
void 'host dependency should be locked when installing'() {
// when
when(cacheManager.runWithGlobalCacheLock(any(GolangDependency), any(Callable))).thenReturn(null)
manager.install(vendorResolvedDependency, resource)
ArgumentCaptor<GolangDependency> captor = ArgumentCaptor.forClass(GolangDependency)
// then
verify(cacheManager).runWithGlobalCacheLock(captor.capture(), any(Callable))
assert captor.getValue().is(hostResolvedDependency)
}


class TestAbstractVcsDependencyManager extends AbstractVcsDependencyManager {

Expand Down

0 comments on commit 7e4a552

Please sign in to comment.