You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2015/10/12 22:02:32 UTC

qpid-proton git commit: NO-JIRA: Fix go code to work under gccgo as well as golang go.

Repository: qpid-proton
Updated Branches:
  refs/heads/master 6859fa307 -> 40630b6c7


NO-JIRA: Fix go code to work under gccgo as well as golang go.

Problem with -race detection under gccgo, disabled.
Go test current directory: golang does not change directory, gccgo changes to test directory.
Fix enum type mismatch seen in Travis builds.
Added go version message to CMake configuration to help with future issues.

Also fixed a race condition in the examples.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/40630b6c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/40630b6c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/40630b6c

Branch: refs/heads/master
Commit: 40630b6c7bee7e720541f49c2d4c6b0f9e7a02a9
Parents: 6859fa3
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Oct 8 14:42:44 2015 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Mon Oct 12 16:01:33 2015 -0400

----------------------------------------------------------------------
 examples/go/CMakeLists.txt                      |  7 +-
 examples/go/electron/broker.go                  |  2 +-
 examples/go/electron/receive.go                 | 28 +++----
 examples/go/electron/send.go                    | 11 +--
 examples/go/electron/util                       |  1 +
 examples/go/example_test.go                     |  4 +-
 examples/go/proton/broker.go                    |  2 +-
 examples/go/proton/util                         |  1 +
 examples/go/util/util.go                        |  3 +-
 proton-c/bindings/go/CMakeLists.txt             | 80 ++++++++++----------
 .../go/src/qpid.apache.org/amqp/types.go        |  5 +-
 .../go/src/qpid.apache.org/amqp/unmarshal.go    |  6 +-
 .../qpid.apache.org/electron/messaging_test.go  |  4 +
 13 files changed, 83 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/go/CMakeLists.txt b/examples/go/CMakeLists.txt
index 1b68ebe..76487fd 100644
--- a/examples/go/CMakeLists.txt
+++ b/examples/go/CMakeLists.txt
@@ -32,13 +32,12 @@ if(BUILD_GO)
 
   add_test(
     NAME go_example_electron_test
-    COMMAND ${CMAKE_CURRENT_BINARY_DIR}/example_test -broker broker
-    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/electron)
+    COMMAND ${CMAKE_CURRENT_BINARY_DIR}/example_test -dir ${CMAKE_CURRENT_BINARY_DIR}/electron -broker broker)
+
 
   add_test(
     NAME go_example_proton_test
-    COMMAND ${CMAKE_CURRENT_BINARY_DIR}/example_test -broker ../proton/broker
-    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/electron)
+    COMMAND ${CMAKE_CURRENT_BINARY_DIR}/example_test -dir ${CMAKE_CURRENT_BINARY_DIR}/electron -broker ../proton/broker)
 
   list(APPEND ADDITIONAL_MAKE_CLEAN_FILES ${examples})
 endif()

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/electron/broker.go
----------------------------------------------------------------------
diff --git a/examples/go/electron/broker.go b/examples/go/electron/broker.go
index 4b877df..0ecfb92 100644
--- a/examples/go/electron/broker.go
+++ b/examples/go/electron/broker.go
@@ -27,7 +27,7 @@ under the License.
 package main
 
 import (
-	"../util"
+	"./util"
 	"flag"
 	"fmt"
 	"net"

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/electron/receive.go
----------------------------------------------------------------------
diff --git a/examples/go/electron/receive.go b/examples/go/electron/receive.go
index 7639375..e450a75 100644
--- a/examples/go/electron/receive.go
+++ b/examples/go/electron/receive.go
@@ -20,7 +20,7 @@ under the License.
 package main
 
 import (
-	"../util"
+	"./util"
 	"flag"
 	"fmt"
 	"log"
@@ -54,9 +54,10 @@ func main() {
 	}
 
 	messages := make(chan amqp.Message) // Channel for messages from goroutines to main()
-	stop := make(chan struct{})         // Closing this channel means the program is stopping.
-	var wait sync.WaitGroup             // Used by main() to wait for all goroutines to end.
-	wait.Add(len(urls))                 // Wait for one goroutine per URL.
+	defer close(messages)
+
+	var wait sync.WaitGroup // Used by main() to wait for all goroutines to end.
+	wait.Add(len(urls))     // Wait for one goroutine per URL.
 
 	_, prog := path.Split(os.Args[0])
 	container := electron.NewContainer(fmt.Sprintf("%v:%v", prog, os.Getpid()))
@@ -87,14 +88,14 @@ func main() {
 			// Loop receiving messages and sending them to the main() goroutine
 			for {
 				rm, err := r.Receive()
-				if err == electron.Closed {
-					return
-				}
-				util.ExitIf(err)
-				select { // Send m to main() or stop
-				case messages <- rm.Message: // Send to main()
-				case <-stop: // The program is stopping.
+				switch err {
+				case electron.Closed:
+					util.Debugf("closed %s", urlStr)
 					return
+				case nil:
+					messages <- rm.Message
+				default:
+					log.Fatal(err)
 				}
 			}
 		}(urlStr)
@@ -105,8 +106,9 @@ func main() {
 
 	// print each message until the count is exceeded.
 	for i := uint64(0); i < *count; i++ {
+		util.Debugf("pre (%d/%d)\n", i, *count)
 		m := <-messages
-		util.Debugf("%s\n", util.FormatMessage(m))
+		util.Debugf("%s (%d/%d)\n", util.FormatMessage(m), i, *count)
 	}
 	fmt.Printf("Received %d messages\n", *count)
 
@@ -116,7 +118,5 @@ func main() {
 		util.Debugf("close %s", c)
 		c.Close(nil)
 	}
-	close(stop) // Signal all goroutines to stop.
 	wait.Wait() // Wait for all goroutines to finish.
-	close(messages)
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/electron/send.go
----------------------------------------------------------------------
diff --git a/examples/go/electron/send.go b/examples/go/electron/send.go
index 94a77e7..6b7aec1 100644
--- a/examples/go/electron/send.go
+++ b/examples/go/electron/send.go
@@ -20,7 +20,7 @@ under the License.
 package main
 
 import (
-	"../util"
+	"./util"
 	"flag"
 	"fmt"
 	"log"
@@ -64,7 +64,7 @@ func main() {
 
 	_, prog := path.Split(os.Args[0])
 	container := electron.NewContainer(fmt.Sprintf("%v:%v", prog, os.Getpid()))
-	var connections []electron.Connection // Store connctions to close on exit
+	connections := make(chan electron.Connection, len(urls)) // Connctions to close on exit
 
 	// Start a goroutine for each URL to send messages.
 	for _, urlStr := range urls {
@@ -82,7 +82,7 @@ func main() {
 			util.ExitIf(err)
 			err = c.Open()
 			util.ExitIf(err)
-			connections = append(connections, c) // Save connection so it will be closed when main() ends
+			connections <- c // Save connection so we can Close() when main() ends
 
 			// Create a Sender using the path of the URL as the AMQP address
 			s, err := c.Sender(electron.Target(url.Path))
@@ -114,8 +114,9 @@ func main() {
 	}
 	fmt.Printf("Received all %v acknowledgements\n", expect)
 
-	wait.Wait()                     // Wait for all goroutines to finish.
-	for _, c := range connections { // Close all connections
+	wait.Wait() // Wait for all goroutines to finish.
+	close(connections)
+	for c := range connections { // Close all connections
 		if c != nil {
 			c.Close(nil)
 		}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/electron/util
----------------------------------------------------------------------
diff --git a/examples/go/electron/util b/examples/go/electron/util
new file mode 120000
index 0000000..40c3fc5
--- /dev/null
+++ b/examples/go/electron/util
@@ -0,0 +1 @@
+../util
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/example_test.go
----------------------------------------------------------------------
diff --git a/examples/go/example_test.go b/examples/go/example_test.go
index a4d7d80..1e497b9 100644
--- a/examples/go/example_test.go
+++ b/examples/go/example_test.go
@@ -32,6 +32,7 @@ import (
 	"net"
 	"os"
 	"os/exec"
+	"path"
 	"path/filepath"
 	"reflect"
 	"strings"
@@ -133,7 +134,7 @@ func exampleCommand(t *testing.T, prog string, arg ...string) (cmd *exec.Cmd) {
 		args = append(args, "-debug=true")
 	}
 	args = append(args, arg...)
-	prog, err := filepath.Abs(prog)
+	prog, err := filepath.Abs(path.Join(*dir, prog))
 	fatalIf(t, err)
 	if _, err := os.Stat(prog); err == nil {
 		cmd = exec.Command(prog, args...)
@@ -271,6 +272,7 @@ var debug = flag.Bool("debug", false, "Debugging output from examples")
 var brokerName = flag.String("broker", "broker", "Name of broker executable to run")
 var count = flag.Int("count", 3, "Count of messages to send in tests")
 var connections = flag.Int("connections", 3, "Number of connections to make in tests")
+var dir = flag.String("dir", "", "Directory containing example sources or binaries")
 var expected int
 
 func TestMain(m *testing.M) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/proton/broker.go
----------------------------------------------------------------------
diff --git a/examples/go/proton/broker.go b/examples/go/proton/broker.go
index dbb4a82..75f14f5 100644
--- a/examples/go/proton/broker.go
+++ b/examples/go/proton/broker.go
@@ -27,7 +27,7 @@ under the License.
 package main
 
 import (
-	"../util"
+	"./util"
 	"flag"
 	"fmt"
 	"io"

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/proton/util
----------------------------------------------------------------------
diff --git a/examples/go/proton/util b/examples/go/proton/util
new file mode 120000
index 0000000..40c3fc5
--- /dev/null
+++ b/examples/go/proton/util
@@ -0,0 +1 @@
+../util
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/examples/go/util/util.go
----------------------------------------------------------------------
diff --git a/examples/go/util/util.go b/examples/go/util/util.go
index f158386..5118467 100644
--- a/examples/go/util/util.go
+++ b/examples/go/util/util.go
@@ -46,8 +46,7 @@ func Debugf(format string, data ...interface{}) {
 // Simple error handling for demo.
 func ExitIf(err error) {
 	if err != nil {
-		log.Println(err)
-		os.Exit(1)
+		log.Fatal(err)
 	}
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/proton-c/bindings/go/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/CMakeLists.txt b/proton-c/bindings/go/CMakeLists.txt
index d24bf2e..11a3b78 100644
--- a/proton-c/bindings/go/CMakeLists.txt
+++ b/proton-c/bindings/go/CMakeLists.txt
@@ -17,52 +17,54 @@
 # under the License.
 #
 
+# Go version
+execute_process(COMMAND ${GO_EXE} version OUTPUT_VARIABLE go_out)
+message(STATUS "Found Go: ${go_out}")
+
 set(GO_BUILD_FLAGS "" CACHE STRING "Flags for 'go build'")
-set(GO_TEST_FLAGS "-v -race" CACHE STRING "Flags for 'go test'")
+
+# Flags that differ for golang go and gcc go.
+if (go_out MATCHES "gccgo")
+  # TODO aconway 2015-10-08: import cycles with -race under gccgo, investigate.
+  set(GO_TEST_FLAGS "-v" CACHE STRING "Flags for 'go test'")
+  set(GO_RPATH_FLAGS -gccgoflags "-Wl,-rpath=${CMAKE_BINARY_DIR}/proton-c")
+else()
+  set(GO_TEST_FLAGS "-v -race" CACHE STRING "Flags for 'go test'")
+  set(GO_RPATH_FLAGS -ldflags "-r ${CMAKE_BINARY_DIR}/proton-c")
+endif()
 
 separate_arguments(GO_BUILD_FLAGS)
 separate_arguments(GO_TEST_FLAGS)
 
-if (BUILD_GO)
-  # Following are CACHE INTERNAL so examples/CMakeLists.txt can see them.
-  set(GO_ENV ${env_py} --
-    "GOPATH=${CMAKE_CURRENT_SOURCE_DIR}"
-    "CGO_CFLAGS=-I${CMAKE_SOURCE_DIR}/proton-c/include"
-    "CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/proton-c"
-    ${GO_EXE} CACHE INTERNAL "Run go with environment set")
-
-  # Set rpath so test and example executables will use the proton library from this build.
-  execute_process(COMMAND ${GO_EXE} version OUTPUT_VARIABLE go_out)
-  if (go_out MATCHES "gccgo")
-    set(GO_RPATH_FLAGS -gccgoflags "-Wl,-rpath=${CMAKE_BINARY_DIR}/proton-c")
-  else()
-    set(GO_RPATH_FLAGS -ldflags "-r ${CMAKE_BINARY_DIR}/proton-c")
-  endif()
-
-  set(GO_BUILD ${GO_ENV} build ${GO_BUILD_FLAGS} ${GO_RPATH_FLAGS} CACHE INTERNAL "Run go build")
-  set(GO_INSTALL ${GO_ENV} install ${GO_BUILD_FLAGS} CACHE INTERNAL "Run go install")
-  set(GO_TEST ${GO_ENV} test ${GO_BUILD_FLAGS} ${GO_RPATH_FLAGS} ${GO_TEST_FLAGS} CACHE INTERNAL "Run go test")
+# Following are CACHE INTERNAL so examples/CMakeLists.txt can see them.
+set(GO_ENV ${env_py} --
+  "GOPATH=${CMAKE_CURRENT_SOURCE_DIR}"
+  "CGO_CFLAGS=-I${CMAKE_SOURCE_DIR}/proton-c/include"
+  "CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/proton-c"
+  ${GO_EXE} CACHE INTERNAL "Run go with environment set")
 
-  # Install packages in the source tree, go tools aren't friendly otherwise.
-  # All build output goes in git-ignored pkg or bin subdirectories.
-  set(q "qpid.apache.org")
-  set(packages ${q}/amqp ${q}/internal ${q}/proton ${q}/electron)
-  add_custom_target(go-packages ALL
-    COMMAND ${GO_INSTALL} ${packages}
-    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-    DEPENDS qpid-proton)
+set(GO_BUILD ${GO_ENV} build ${GO_BUILD_FLAGS} ${GO_RPATH_FLAGS} CACHE INTERNAL "Run go build")
+set(GO_INSTALL ${GO_ENV} install ${GO_BUILD_FLAGS} CACHE INTERNAL "Run go install")
+set(GO_TEST ${GO_ENV} test ${GO_BUILD_FLAGS} ${GO_RPATH_FLAGS} ${GO_TEST_FLAGS} CACHE INTERNAL "Run go test")
 
-  add_test(
-    NAME go_test_packages
-    COMMAND ${GO_TEST} ${packages}
-    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
+# Install packages in the source tree, go tools aren't friendly otherwise.
+# All build output goes in git-ignored pkg or bin subdirectories.
+set(q "qpid.apache.org")
+set(packages ${q}/amqp ${q}/internal ${q}/proton ${q}/electron)
+add_custom_target(go-packages ALL
+  COMMAND ${GO_INSTALL} ${packages}
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+  DEPENDS qpid-proton)
 
-  list(APPEND ADDITIONAL_MAKE_CLEAN_FILES
-    ${CMAKE_CURRENT_SOURCE_DIR}/pkg
-    ${CMAKE_CURRENT_SOURCE_DIR}/bin)
+add_test(
+  NAME go_test_packages
+  COMMAND ${GO_TEST} ${packages}
+  WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
 
-  set (GO_INSTALL_DIR ${SHARE_INSTALL_DIR}/gocode/src CACHE PATH "Installation directory for Go code")
-  mark_as_advanced (GO_INSTALL_DIR)
-  install(DIRECTORY src/qpid.apache.org DESTINATION ${GO_INSTALL_DIR} COMPONENT Go)
+list(APPEND ADDITIONAL_MAKE_CLEAN_FILES
+  ${CMAKE_CURRENT_SOURCE_DIR}/pkg
+  ${CMAKE_CURRENT_SOURCE_DIR}/bin)
 
-endif(BUILD_GO)
+set (GO_INSTALL_DIR ${SHARE_INSTALL_DIR}/gocode/src CACHE PATH "Installation directory for Go code")
+mark_as_advanced (GO_INSTALL_DIR)
+install(DIRECTORY src/qpid.apache.org DESTINATION ${GO_INSTALL_DIR} COMPONENT Go)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
index 131c974..796da66 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
@@ -84,9 +84,10 @@ func (t Type) String() string {
 		return "list"
 	case C.PN_MAP:
 		return "map"
-	case C.PN_INVALID:
-		return "no-data"
 	default:
+		if uint32(t) == uint32(C.PN_INVALID) {
+			return "no-data"
+		}
 		return fmt.Sprintf("unknown-type(%d)", t)
 	}
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
index 61c6d3f..751921d 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
@@ -446,7 +446,8 @@ func rewindUnmarshal(v interface{}, data *C.pn_data_t) {
 func getInterface(data *C.pn_data_t, v *interface{}) {
 	pnType := C.pn_data_type(data)
 	switch pnType {
-	case C.PN_NULL, C.PN_INVALID: // No data.
+	// Note PN_INVALID is defined outside the enum, older Go versions don't consider it a C.pn_type_t
+	case C.PN_NULL, C.pn_type_t(C.PN_INVALID): // No data.
 		*v = nil
 	case C.PN_BOOL:
 		*v = bool(C.pn_data_get_bool(data))
@@ -512,7 +513,8 @@ func getMap(data *C.pn_data_t, v interface{}) {
 				}
 			}
 		}
-	case C.PN_INVALID: // Leave the map empty
+		// Note PN_INVALID is defined outside the enum, older Go versions don't consider it a C.pn_type_t
+	case C.pn_type_t(C.PN_INVALID): // Leave the map empty
 	default:
 		panic(newUnmarshalError(pnType, v))
 	}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/40630b6c/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go b/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
index 474bad7..3b315cd 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/electron/messaging_test.go
@@ -117,8 +117,11 @@ func TestClientSendServerReceive(t *testing.T) {
 	for i := 0; i < nLinks; i++ {
 		for j := 0; j < nMessages; j++ {
 			var sm SentMessage
+
 			// Client send
+			sendDone := make(chan struct{})
 			go func() {
+				defer close(sendDone)
 				m := amqp.NewMessageWith(fmt.Sprintf("foobar%v-%v", i, j))
 				var err error
 				sm, err = s[i].Send(m)
@@ -137,6 +140,7 @@ func TestClientSendServerReceive(t *testing.T) {
 			}
 
 			// Should not be acknowledged on client yet
+			<-sendDone
 			if d, err := sm.DispositionTimeout(0); err != Timeout || NoDisposition != d {
 				t.Errorf("want [no-disposition/timeout] got [%v/%v]", d, err)
 			}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org